I was following the android lessons on codelabs and they were introducing databinding. According to the code, all i needed to do was to enable databinding within the build.gradle file as below:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.lesson4"
minSdkVersion 18
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'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
However, the project fails to build into the emulator, and I am presented with the error code: Unable to load class 'javax.xml.bind.JAXBException'.
I also went further to amend the XML file of activity_main to wrap the ConstraintLayout within a Layout tag, but I think the error is somewhere within the gradle build portion instead.
I have tried various methods, such as apply plugin: 'kotlin-kapt' as well as including the kotlin dependencies, but the same error still persist.
I have also tried cleaning the project and rebuilding it.
I have also tried creating a brand new project, and only enabling databinding... The same error persists.
Hope someone can enlighten me about how to get databinding working in intellij for android?
Upon some research I have found that data binding will throw errors while using Java 9+.
All you have to do is set your Java to version 8 and it should work.
I don't want to use Java 8
Then you have to manually add the JAX-B dependencies
kapt "com.sun.xml.bind:jaxb-core:2.3.0.1"
kapt "javax.xml.bind:jaxb-api:2.3.1"
kapt "com.sun.xml.bind:jaxb-impl:2.3.2"
annotationProcessor "com.sun.xml.bind:jaxb-core:2.3.0.1"
annotationProcessor "javax.xml.bind:jaxb-api:2.3.1"
And apply the kotlin-kapt plugin with:
apply plugin: 'kotlin-kapt'
Related
I am learning to write android apps by watching some tutorials on youtube. I follow the tutorials and try to add the recyclerview in the xml file. When I click the download button next to the recyclerview, the following message is shown:
"This operation requires the library androidx.recyclerview:recyclerview:+.
Problem: Inconsistencies in the existing project dependencies found.
Version incompatibility between:
- androidx.appcompat:appcompat:1.1.0#aar
and:
- androidx.core:core-ktx:1.1.0#aar
With the dependency:
- androidx.annotation::1.1.0
versus:
- androidx.annotation::2.0.0
The project may not compile after adding this library.
Would you like to add it anyway?"
If I choose OK and go ahead, the preview screen becomes grey.
What should I do to solve the problem?
The same problem occurs when I want to add the cardview in the xml file.
thanks in advance!!!!
The build.gradle is below:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.smartherd.msgshareapp"
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Just build the project again and manually refresh the layout. :)
I am implementing OCR results in android using kotlin language by this tutorial
I am unable to solve this ActivityCompat error
import android.support.v4.app.ActivityCompat
My Gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.ocrofflinesample"
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
// implementation 'androidx.support:appcompat-v7:'
implementation 'androidx.core:core-ktx:1.0.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.gms:play-services-vision:15.0.1'
implementation "org.jetbrains.anko:anko:0.10.4"
// Logger
implementation 'com.orhanobut:logger:2.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
How to resolve this `ActivityCompat error`?
You have to use Androidx dependency. Change the android.support.v4.app.ActivityCompat to androidx.core.app.ActivityCompat
Check this out for pre-Androidx to Androidx dependencies mapping.
You might have either used AndroidX while creating project, or you have used AndroidX dependencies in non - androidX artifact.
Either you need to migrate it to androidX as suggested above.
Also, if you have used app:layout_scrollFlags in layouts, you
might wanna check out the scroll constants after refactor because
recently when I refactored, I didn't get any build error but when the
activity with scrollFlags loaded, it crashed and upon finding
out, it was a refactor issue due to that it was unable to change
constant names as per AndroidX.
I am new to Android. Here I am trying to add data binding to my android app for that I enabled data binding to true in-app level gradle file but the problem is it's not syncing it gives some error like this.
Gradle DSL method not found: 'dataBinding()'
Possible causes:
The project 'TriviaApp' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 3.4.1 and sync project
The project 'TriviaApp' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file
The build file may be missing a Gradle plugin.
Apply Gradle plugin
this is My app level gradle file code
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.triviaapp"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding(
enabled: true
)
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
}
Can anyone please help me to figure out what am I doing wrong and help me to fix this.
You should use
dataBinding {
enabled = true
}
Make sure, your build.gradle is
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
allprojects {
repositories {
jcenter()
}
}
Android newbie here. I don't know why but I can't add specific items/elements to the activity_main.xml (NestedScrollView, CardViev, Google MapView, etc). If I try to add, let's say Google MapView, a message appears that says this :
This operation requires the library com.google.android.gms:play-services-maps:+.
Problem: Inconsistencies in the existing project dependencies found.
Version incompatibility between:
- com.google.android.material:material:1.0.0
and:
- androidx.appcompat:appcompat:1.0.0
With the dependency:
- org.mockito:mockito-core:1.9.5
versus:
- org.mockito:mockito-core:2.19.0
The project may not compile after adding this library.
Would you like to add it anyway?.
Does anybody know what seems to be the problem? Build.gradle is displayed below.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 25
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation 'com.google.android.material:material:1.0.0'
}
The first of your problems is that you try to use Views, items, constants, etc, of a library that does not exist in your project, with these implementations it is more than enough for you to move forward, the problem with mockito is that you possibly implemented two versions and maybe the first version uses discontinued components, and therefore. Gradle will always look for the latest version, however both libraries need to live together, I recommend that you remove mockito 1.9.5 and try to synchronize again, I hope it was helpful , good luck!
apply plugin: 'com.google.gms.google-services'
dependencies{
implementation 'com.google.android.gms:play-services-cast-framework:10.0.1'
}
I was working with android jetback after add recycle view with androidx and databinding and live datait started showing
android.support.v4.app.INotificationSideChannel$Stub.
I have tried a lot of solutions so far but nothing has helped. Why does it show this error when I am not using any support library and what can I do to solve it?
update :
after retracing my steps i removed the data binding and every thing worked fine can any one explain
Here is my gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.ahmedmubarak.pixeapp"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
implementation 'androidx.cardview:cardview:1.0.0-beta01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-beta01'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.android.volley:volley:1.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
}
I added this to build.gradle to remove the error
configurations {
implementation {
exclude group: 'com.android.support', module: 'support-v4'
}
}
Unfortunately, I predict that you'll see a new error (at run-time) like this:
java.lang.NoClassDefFoundError: Failed resolution of:
I believe this is an AndroidX issue that occurs with lots of support libraries that have yet to be updated to support AndroidX.
I have a similar problem. In my case, it was because I am using Glide library and androidx. This solution works for me:
Set enableJetifier value to true
Update Gradle build tool to 3.3.0-alpha08 with Gradle version 4.9
source