I'm having trouble implementing data binding in my Android Studio project. I get the following error:
Cannot access 'androidx.databinding.Observable' which is a supertype
of 'com.russ.beatbox.databinding.MainActivityBinding'. Check your
module classpath for missing or conflicting dependencies
Even though i have all the Gradle dependencies and the binding class is generated. I've tried rebuilding, invalidate cache/restart, clean project, renaming the file, and using different Gradle import syntax, nothing seems to work. Is this Android Studio bug?
Here's my MainActivity, the error comes from binding.recView.apply:
package com.russ.beatbox
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.GridLayoutManager
import com.russ.beatbox.databinding.MainActivityBinding
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding: MainActivityBinding =
DataBindingUtil.setContentView(this, R.layout.main_activity)
binding.recView.apply{
layoutManager = GridLayoutManager(context, 3)
}
}
}
My layout:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rec_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</layout>
And my module Gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdk 31
defaultConfig {
applicationId "com.russ.beatbox"
minSdk 23
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
buildFeatures{
dataBinding = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
In your module build.gradle file add the implementation for databinding, fragment, and livedata.
By the time you are done, your file should look like this:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileSdk 30
defaultConfig {
configurations.all {
resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
}
applicationId "org.evolvedigital.unscrambleit"
minSdk 23
targetSdk 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
dataBinding = true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.databinding:databinding-runtime:7.0.3'
implementation 'androidx.fragment:fragment-ktx:1.4.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
If you already have these dependencies, update them to the latest version. Note that the minimum compileSdk version to use the latest dependencies in the android library is 31, so you may want to update your project accordingly if it's not up to date
Try with removing layout tag form xml file it is used when you have data that need to bind with views
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rec_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
also try to update build file like
buildFeatures {
viewBinding true
dataBinding true
}
Related
I am using the following in android studio
View binding
Navigation
The bottom menu when clicked the app does not go to new destination
Here is the code:
App level build.gradle file:
buildscript {
repositories {
google()
}
dependencies {
def nav_version = "2.5.3"
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}
}
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
id 'com.google.dagger.hilt.android' version "2.44" apply false
}
Module level build.gradle file:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
id "com.google.dagger.hilt.android"
id "androidx.navigation.safeargs.kotlin"
}
android {
namespace 'com.example.newsapiclient'
compileSdk 32
defaultConfig {
applicationId "com.example.newsapiclient"
minSdk 26
targetSdk 32
versionCode 1
versionName "1.0"
buildConfigField("String","API_KEY", MY_KEY)
buildConfigField("String","BASE_URL",MY_URL)
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding = true
}
}
dependencies {
def lifecycle_version = "2.5.1"
def nav_version = "2.5.3"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.code.gson:gson:2.10.1'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"
// ViewModel
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
// ViewModel utilities for Compose
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version")
// LiveData
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation("com.google.dagger:hilt-android:2.44")
kapt("com.google.dagger:hilt-android-compiler:2.44")
implementation("androidx.navigation:navigation-fragment-ktx:$nav_version")
implementation("androidx.navigation:navigation-ui-ktx:$nav_version")
implementation 'com.github.bumptech.glide:glide:4.14.2'
kapt 'com.github.bumptech.glide:compiler:4.14.2'
testImplementation 'junit:junit:4.13.2'
testImplementation "com.squareup.okhttp3:mockwebserver:4.10.0"
testImplementation "com.google.truth:truth:1.1.3"
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
navigation xml file (nav_graph.xml):
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/nav_graph"
app:startDestination="#id/newsFragment">
<fragment
android:id="#+id/newsFragment"
android:name="com.example.newsapiclient.NewsFragment"
android:label="fragment_news"
tools:layout="#layout/fragment_news" >
<action
android:id="#+id/action_newsFragment_to_infoFragment"
app:destination="#id/infoFragment" />
</fragment>
<fragment
android:id="#+id/saveFragment"
android:name="com.example.newsapiclient.SaveFragment"
android:label="fragment_save"
tools:layout="#layout/fragment_save" >
<action
android:id="#+id/action_saveFragment_to_infoFragment"
app:destination="#id/infoFragment" />
</fragment>
<fragment
android:id="#+id/infoFragment"
android:name="com.example.newsapiclient.InfoFragment"
android:label="fragment_info"
tools:layout="#layout/fragment_info" />
</navigation>
activity_main.xml:
class MainActivity : AppCompatActivity() {
private lateinit var binding : ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val navHostFragment = supportFragmentManager
.findFragmentById(R.id.fragmentContainerView) as NavHostFragment
val navController = navHostFragment.navController
}
}
bottom navigation menu (bottom_menu.xml)
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/newsFragment"
android:icon="#drawable/ic_baseline_live_tv_24"
android:title="News Headlines" />
<item
android:id="#+id/saveFragment"
android:icon="#drawable/ic_baseline_save_24"
android:title="Save News" />
</menu>
When I click on the bottom menu bottom, the app does not display the second destination in navigation graph whichhas id fragment_save.
You missing code to link bottom navigation with nav controller.
Add below code in onCreate method of your MainActivity.
val navView: BottomNavigationView = findViewById(R.id.bottom_nav_view)
navView.setupWithNavController(navController)
I am a Android Studio starter and I want to create a Recycle View for practical. First, I have followed this video to study ( https://www.youtube.com/watch?v=j29YnF-mPd8 ) but at the end, I noticed an "Unresolved reference: recyclerView" error. How I can solve it ?
package com.example.recycleview
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
class MainActivity : AppCompatActivity() {
private var layoutManager: RecyclerView.LayoutManager?=null
private var adapter:RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder>?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
layoutManager=LinearLayoutManager(this)
recyclerView.layoutManager=layoutManager //here got problem
adapter=RecyclerViewAdapter()
recyclerView.adapter=adapter //and here got problem
}
}
Below are my build gradle :
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.recycleview"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation fileTree(dir: 'libs',includes: ['*.jar'])
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
// For control over item selection of both touch and mouse driven selection
implementation 'androidx.recyclerview:recyclerview-selection:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
}
My main activity XML file :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Thx for giving solution to help me !
You have to declare it before using it, just add:
val recyclerView: RecyclerView = findViewById(R.id.recyclerView)
inside onCreate()
When you are calling
recyclerView.layoutManager=layoutManager //here got problem
adapter=RecyclerViewAdapter()
recyclerView.adapter=adapter //and here got problem
You are using the recyclerView variable without having it declared and initialized first.
Initialize it before using it with a call like this:
val recyclerView: RecyclerView = findViewById(R.id.recyclerView)
recyclerView.layoutManager=layoutManager //here got problem
adapter=RecyclerViewAdapter()
recyclerView.adapter=adapter //and here got problem
I add Navigation Drawer Activity to my project in Android Studio. I got this problem:
This operation requires the libraries androidx.navigation:navigation-fragment:+, androidx.navigation:navigation-ui:+.Problem: Inconsistencies in the existing project dependencies found.Version incompatibility between:- androidx.appcompat:appcompat:1.1.0#aarand:- androidx.appcompat:appcompat:1.1.0#aarWith the dependency:- androidx.annotation:*:1.1.0versus:- androidx.annotation:*:2.0.0The project may not compile after adding these libraries.Would you like to add them anyway?
I clicked OK and when I install the app in my phone everything is OK except that the fragments do not switch when you select another item on the menu. I don't think this is normal because I have seen tutorials and when you added it automaticaly works without any changes.
Anyone know where the problem is?
My gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.example.opencvapplication"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation project(path: ':java')
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.3.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.ankuryadav.lib:volleylib:1.0.3'
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.42.6'
implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.42.6'
}
And the Activity
public class MainActivity2 extends AppCompatActivity {
private AppBarConfiguration mAppBarConfiguration;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)
.setDrawerLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_activity2, menu);
return true;
}
#Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|| super.onSupportNavigateUp();
}
}
Found the solution: Why doesn't the navigation drawer activity work?
The activity_main.xml it's created incorrectly because the part should be after DrawerLayout.
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
I post this because it wasn´t my mistake, it's an error from Android Studio template, so I hope that if someone see this doesn't waste as much time as I did.
I'm binding data between android fragment and ViewModel in kotlin. Compiler throws
error: cannot find symbolimport >frydzej.yerbet.databinding.FragmentCollectionBindingImpl
I have tried to change gradle version to 3.2.1 and databinding compiler version to 3.2.1. But with same result.
My Android Studio version is 3.3 RC 3
This is my project gradle buildscript
buildscript {
ext.kotlin_version = '1.3.11'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-rc03'
classpath "org.jetbrains.kotlin:kotlin-gradle-
plugin:$kotlin_version"
classpath 'android.arch.navigation:navigation-safe-args-gradle-
plugin:1.0.0-alpha09'
}
}
and app gradle
dataBinding{
enabled = true
}
dependencies {
def lifecycle_version = "2.0.0"
def room_version = "2.0.0"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
implementation 'com.google.android.material:material:1.1.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha09"
implementation "android.arch.navigation:navigation-ui-ktx:1.0.0-alpha09"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation 'com.cuneytayyildiz:onboarder:1.0.3'
implementation 'com.android.support:design:28.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
testImplementation 'junit:junit:4.12'
debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
fragment_collection.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable name="viewModel" type="frydzej.yerbet.viewModels.CollectionViewModel"/>
</data>
<FrameLayout
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".Views.CollectionFragment">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/add_item_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="#drawable/ic_add"
android:onClick="#{() -> viewModel.addFabClicked()}"
android:layout_margin="16dp"
app:fabSize="normal"/>
</FrameLayout>
</layout>
and the Fragment view code:
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val binding: FragmentCollectionBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_collection, container, false)
val view: View = binding.root
val viewModel: CollectionViewModel = ViewModelProviders.of(this).get(CollectionViewModel::class.java)
binding.viewModel = viewModel
return view
}
In MainActivity databinding there is either
ActivityMainBinding
and
ActivityMainBindingImpl,
but in CollectionFragment only
FragmentCollectionBinding
is created
I had the same issue:
The solution eventually was that I misspelled one of the values in my fragments XML file.
Take a look at the android:onclick parameter with an additional () I mistakenly added
WRONG
<Button
android:id="#+id/end_game_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="#string/end_game"
android:theme="#style/SkipButton"
android:onClick="#{() -> gameViewModel.onGameFinished()()}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline" />
RIGHT
<Button
android:id="#+id/end_game_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="#string/end_game"
android:theme="#style/SkipButton"
android:onClick="#{() -> gameViewModel.onGameFinished()}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline" />
I will advise you check through your fragment's XML file for any typo or misspelled variable names and correct them. This solved my issue.
These errors only get caught at compile-time and points to the generated databinding files, making it hard to debug.
Okay, I found solution. My ViewModel constructor had one parameter and I had to create custom ViewModelProviderFactory in order to work. It wasn't Android Studio fault.
Code before:
val viewModel: CollectionViewModel = ViewModelProviders.of(this).get(CollectionViewModel::class.java)
Code after:
val viewModel: CollectionViewModel = ViewModelProviders.of(this, CollectionViewModelFactory(activity!!.application)).get(CollectionViewModel::class.java)
where
activity!!.application
is argument to my ViewModel
I create new project and select minimum sdk 2.3.3 gingerbread then select Google map Activity . android studio default preparations do . this project work on api 11 and above و but in api 10(for example Galaxy Y s5360, not install google play services) message show "get google play services" . For example, I have some applications that run in this version and this device(s5360) google map work without any problem .
please help ( sorry for my english)
my build.gradle is :
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.ehm.tantum"
minSdkVersion 10
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.android.support:support-v4:21.0.3' }
My mainfest is :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ehm.tantum" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key" /> // i have API key this prject
<activity
android:name=".MapsActivity"
android:label="#string/title_activity_maps" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
my mapActivity :
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
}
#Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
My libs folder default is empty .
please help .
If you have not installed google play services on your device, maps will never work.
You need the same version you use for compiling the app (6.5.87 according to your buildfile)
The fact that other apps are working, means (or i suppose at least) that is because you have an outdated version of play services and the other apps are compiled with older version of play services.
Try to update services on your device