I'm trying to get datas from my class to my xml file so i tried to use data binding. But data-binding library does not working. When i write <data in my xml file, compiler does not shows anything. How can i solve this problem ? Otherwise how can i get datas from class to xml file without data binding ? Xml belongs to a fragment view.
'''plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id("androidx.navigation.safeargs")
id 'com.google.gms.google-services'
id "org.jetbrains.kotlin.kapt"
id 'kotlin-kapt'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.cagataysencan.forumfisk_it"
minSdkVersion 24
targetSdkVersion 30
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
}
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.5.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
//Navigation v Google Maps
implementation("androidx.navigation:navigation-fragment-ktx:2.3.5")
implementation("androidx.navigation:navigation-ui-ktx:2.3.5")
implementation 'com.google.android.gms:play-services-maps:17.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Firebase
implementation platform('com.google.firebase:firebase-bom:28.2.0')
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-firestore-ktx'
implementation 'com.google.firebase:firebase-storage-ktx'
// Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
// ViewModel
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1")
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.3.1")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:2.3.1")
implementation("androidx.lifecycle:lifecycle-service:2.3.1")
implementation("androidx.lifecycle:lifecycle-process:2.3.1")
implementation("androidx.lifecycle:lifecycle-reactivestreams-ktx:2.3.1")
testImplementation("androidx.arch.core:core-testing:2.1.0")
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.8.1'
implementation 'com.squareup.retrofit2:converter-gson:2.8.1'
implementation "com.squareup.retrofit2:adapter-rxjava2:2.8.1"
// RX Java
implementation "io.reactivex.rxjava2:rxjava:2.2.9"
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
// Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
// Room
implementation 'androidx.room:room-rxjava2:2.3.0'
implementation "androidx.room:room-guava:2.3.0"
implementation "androidx.room:room-ktx:2.3.0"
implementation ("androidx.room:room-runtime:2.3.0")
annotationProcessor "androidx.room:room-compiler:2.3.0"
kapt("androidx.room:room-compiler:2.3.0")
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1"
}**
Remove the lines:
databinding {
enabled=true
}
Also, remove viewBinding since there is no need for it if you are already using dataBinding..
Move buildFeatures out of buildTypes so that it should be like this
android {
...
buildTypes {
...
}
buildFeatures {
dataBinding true
}
}
And when you want to use dataBinding, make sure you enclose your layout with the <layout> tag to signify that the layout is eligible for dataBinding. So each xml file you want to bind should have the <layout> tag and can be like this for example:
<layout 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">
<data>
...
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
...
...
</layout>
Please match some line of plugin and dependency and version with kotlin and databinding in your gradle file that what you missing please check
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
dependencies{
kapt 'com.android.databinding:compiler:4.0.0'
}
ext.kotlin_version = '1.4.10'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Hope it may help you
Related
I am trying to use Safe Args with the NavigationComponent. I have followed a tutorial, but I have problems because any class is generated automatically, so I can't pass any arguments because Classes (obviously) are not recognized
These are my Gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
def nav_version = "2.4.1"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath 'com.android.tools.build:gradle:7.1.0'
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
id 'androidx.navigation.safeargs'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.frangela"
minSdk 21
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'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}
dependencies {
def nav_version = "2.4.1"
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
implementation 'com.google.firebase:firebase-database:20.0.3'
implementation 'com.google.firebase:firebase-common-ktx:20.0.0'
implementation 'com.google.android.gms:play-services-maps:18.0.1'
implementation 'com.google.android.gms:play-services-location:19.0.1'
implementation 'com.google.firebase:firebase-crashlytics-buildtools:2.8.1'
testImplementation 'junit:junit:'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation platform('com.google.firebase:firebase-bom:29.0.3')
implementation "androidx.recyclerview:recyclerview:1.2.1"
implementation 'com.firebaseui:firebase-ui-database:6.2.1'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.android.gms:play-services-auth:20.1.0'
}
This is the xml code:
<?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/mobile_navigation"
app:startDestination="#+id/nav_home">
<fragment
android:id="#+id/nav_home"
android:name="com.example.frangela.ui.home.HomeFragment"
android:label="#string/menu_home"
tools:layout="#layout/fragment_home" />
<fragment
android:id="#+id/nav_gallery"
android:name="com.example.frangela.ui.gallery.GalleryFragment"
android:label="#string/menu_gallery"
tools:layout="#layout/fragment_gallery" />
<fragment
android:id="#+id/nav_slideshow"
android:name="com.example.frangela.ui.slideshow.InserisciSpesaFragment"
android:label="#string/menu_slideshow"
tools:layout="#layout/fragment_inserisci" >
<argument
android:name="descrizione"
app:argType="string" />
<argument
android:name="ammontare"
app:argType="float" />
</fragment>
<fragment
android:id="#+id/nav_stipendio"
android:name="com.example.frangela.ui.stipendio.InserisciStipendioFragment"
android:label="#string/menu_stipendio"
tools:layout="#layout/fragment_stipendio" />
<fragment
android:id="#+id/nav_resoconto"
android:name="com.example.frangela.ui.resocard.ResocardFragment"
android:label="#string/Resoconto"
tools:layout="#layout/fragment_resocard" >
<action
android:id="#+id/action_nav_resoconto_to_nav_slideshow"
app:destination="#id/nav_slideshow" />
</fragment>
</navigation>
After that I resync my project and rebuild, but nothing changes.
I tried to follow different tutorials and questions but none of them solved my problem. What am I missing?
Thanks in advance
After some days, I have found that the code has been generated, but in different folders, so that I cannot see them
As normal I was working on my actual project and I wanted to add something new to an old activity. When I opened the .java file a new error has shown with a reason that I can not think about. It says that the FirebaseAuth symbol cannot be resolved. I checked my Gradle ( which is updated to the latest version) and the code but I can't find a solution. I would really appreciate it if someone would help me.
A screenshot:
The Gradle module:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.diligent"
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments += [
"room.schemaLocation":"$projectDir/schemas".toString(),
"room.incremental":"true",
"room.expandProjection":"true"]
}
}
}
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.core:core-ktx:1.3.2'
implementation "androidx.multidex:multidex:2.0.1"
implementation 'com.google.android.gms:play-services-ads:20.0.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.github.congtung10t2:circularseekbarplus:1.0'
implementation 'com.google.firebase:firebase-auth:20.0.4'
implementation 'com.google.firebase:firebase-database:19.7.0'
}
And Project:
buildscript {
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.google.gms:google-services:4.3.5'
classpath "com.google.gms:google-services:4.3.5"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://jitpack.io"
}
}
}
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.android.gms:play-services-gcm:17.0.0'
I have updated my Firebase Crashlytics from
implementation 'com.google.firebase:firebase-crashlytics:17.1.1'
to
implementation 'com.google.firebase:firebase-crashlytics:17.3.0'
Now I am getting this error:
error: package com.google.firebase.iid does not exist
When I try to import this:
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;
This is my project level build.gradle file:
buildscript {
ext {
kotlin_version = '1.3.72'
}
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.google.gms:google-services:4.3.4'
classpath 'com.google.firebase:perf-plugin:1.3.4'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.20" }
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
This is my app level build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.firebase.crashlytics'
android {
compileSdkVersion 30
defaultConfig {
applicationId "..."
minSdkVersion 16
targetSdkVersion 30
versionCode ...
versionName "..."
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled true
//shrinkResources true NOT SUPPORTED FOR DYNAMIC MODULES
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
multiDexEnabled true
}
debug {
multiDexEnabled true
}
}
dynamicFeatures = [":premium", ':tutorial']
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api 'androidx.appcompat:appcompat:1.2.0'
api 'com.google.android.material:material:1.2.1'
api 'androidx.constraintlayout:constraintlayout:2.0.4'
api 'com.google.android.play:core:1.8.3'
api 'com.google.firebase:firebase-analytics:18.0.0'
api 'com.google.firebase:firebase-perf:19.0.10'
api 'com.google.firebase:firebase-invites:17.0.0'
api 'com.google.firebase:firebase-firestore:22.0.0'
api 'androidx.legacy:legacy-support-v4:1.0.0'
api 'com.google.firebase:firebase-config:20.0.1'
implementation 'com.google.firebase:firebase-appindexing:19.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
api 'androidx.navigation:navigation-fragment:2.3.1'
api 'androidx.cardview:cardview:1.0.0'
api 'androidx.recyclerview:recyclerview:1.1.0'
api 'androidx.preference:preference:1.1.1'
implementation 'com.google.firebase:firebase-crashlytics:17.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'
api 'com.google.firebase:firebase-auth:20.0.1'
api 'com.google.zxing:core:3.3.3'
api 'com.android.billingclient:billing:3.0.1'
//api 'com.facebook.android:facebook-android-sdk:5.15.3'
implementation 'com.google.android.gms:play-services-ads-lite:19.5.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.android.datatransport:transport-runtime:2.2.5'
}
The error doesn't happen with firebase crashlytics dependency version 17.1.1 and below.
I have already tried:
Rebuilding Project
Cleaning Project
Invalidating Cache and Restarting
The solution to this problem was that FirebaseInstanceId was depreciated. This means that it was removed from the library.
You can find more information about it here: https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId
firstly my module build.gradle was like this:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.depressionanalysis"
minSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
buildToolsVersion '28.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.firebase:firebase-firestore:17.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.guava:guava:27.0.1-jre'
implementation 'com.loopj.android:android-async-http:1.4.9'
}
which resulted in this warning:
" The app gradle file must have a dependency on com.google.firebase:firebase-core for Firebase services to work as intended. "
so i tried to add it in (and updated firestore as well)
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.depressionanalysis"
minSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
buildToolsVersion '28.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.firebase:firebase-firestore:21.4.2'
implementation 'com.google.firebase:firebase-core:17.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.guava:guava:27.0.1-jre'
implementation 'com.loopj.android:android-async-http:1.4.9'
}
but got this error
" Manifest merger failed : Attribute application#appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:10:5-46:19 to override. "
How do i fix it? I've tried out a few solutions found here but to no avail.. Thanks in advance! Let me know if any other codes are needed!!
You are using the latest version of firestore:
com.google.firebase:firebase-firestore:21.4.2
and on June 2019, firebase started supporting androidX, therefore you need to migrate to androidX to be able to use firebase.
The updated libraries will not work unless you make the following changes in your app:
Upgrade com.android.tools.build:gradle to v3.2.1 or later.
Upgrade compileSdkVersion to 28 or later.
Update your app to use Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.
Check how to migrate:
https://developer.android.com/jetpack/androidx/migrate
Actually, for the same library, you have different versions via different sources, You have support library as well as their AndroidX version, For Now, you can try solving it using
tools:replace="android:appComponentFactory
attribute as given in your error itself.
Go to your AndroidManifest file add this attribute like below.
<application
android:name=".AbcApplication"
tools:replace="android:appComponentFactory
>
</application>
for me i have add two attribute in AndroidMenifest.xml
tools:replace="android:appComponentFactory"
android:appComponentFactory="androidx"
full tag it like :
<application
android:allowBackup="true"
android:icon="#mipmap/logo"
android:label="#string/app_name"
android:roundIcon="#mipmap/logo"
android:theme="#style/AppTheme"
tools:replace="android:appComponentFactory"
android:appComponentFactory="androidx"
tools:ignore="GoogleAppIndexingWarning">
and your project should be in Androidx.
I've searched through previous post and can't find the answer to my question here is my code from my build.gradle file.
Error: A problem occurred evaluating project ':app'.
Could not get unknown property 'implementation' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.loganwiley.findmyphone"
minSdkVersion 17
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
compileKotlin {
kotlinOptions.suppressWarnings = true
}
compileKotlin {
kotlinOptions {
suppressWarnings = true
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'+
implementation 'com.android.support.constraint:constraint-layout:1.0.2'+
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'+
implementation 'com.google.firebase:firebase-auth:10.2.4'+
implementation 'com.google.firebase:firebase-database:10.2.4'+
implementation 'com.google.android.gms:play-services-maps:10.2.4'+
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'+
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
repositories {
mavenCentral()
}
apply plugin: 'com.google.gms.google-services'
Remove all those weird plus signs (+) you have after many of your dependency declerations. So, for instance, instead of:
implementation 'com.android.support:appcompat-v7:28.0.0'+
Write:
implementation 'com.android.support:appcompat-v7:28.0.0'