Issue with databinding using Kotlin for Android - android

I am trying to enable data binding for my Android project using Kotlin. I have Kotlin plugin enabled, but I am not able to enable data binding I keep getting the following error
Error:(66, 0) Could not find method kapt() for arguments [com.android.databinding:compiler:2.0.0-beta6] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
I have the following dependencies for data binding in my gradle file
dependencies {
...
kapt 'com.android.databinding:compiler:2.0.0-beta6'
}
kapt {
generateStubs = true
}

Edit: With Kotlin 1.1 and Kapt3 it works slightly different:
in your project build.gradle:
buildscript {
ext {
...
plugin_version = "2.3.1"
kotlin_version = "1.1.2-3"
...
}
...
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.android.tools.build:gradle:$plugin_version"
...
}
}
and in your app build.gradle:
apply plugin: "kotlin-android"
apply plugin: "kotlin-kapt"
...
android {
...
dataBinding {
enabled = true
}
...
}
dependencies {
...
kapt "com.android.databinding:compiler:$plugin_version"
...
}
It's really important that the databinding compiler version and the plugin version are identical.
Also note that with kapt3, you shouldn't use the generateStubs flag anymore.
Old Answer
Having the Android Studio plugin enabled isn't enough, you also need to adjust your gradle files a little bit (add and apply the kotlin-gradle-plugin)
Here are excerpts of my gradle files with working Java and Kotlin Databinding
In your project build.gradle:
buildscript {
...
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.0.5"
classpath 'com.android.tools.build:gradle:2.2.3'
...
}
}
and in your app build.gradle:
apply plugin: "kotlin-android"
...
android {
...
dataBinding {
enabled = true
}
...
}
kapt {
generateStubs = true
}
dependencies {
...
kapt "com.android.databinding:compiler:2.2.0"
...
}
(I'm using a newer version of the databinding compiler here, you probably should do this as well)

Try to include the missing blocks in your gradle files with the help of the following reference gradle file source.
App level Build.Gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.example.adventure.abc"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin/com/dougritter/marvelmovies'
}
dataBinding {
enabled = true
}
}
kapt {
generateStubs = true
}
dependencies {
//Compatibility
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
kapt 'com.android.databinding:compiler:2.3.0'
//Libraries
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-vector-drawable:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile project(':domain')
compile project(':androidutils')
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.jakewharton.timber:timber:4.5.1'
}
Project level Build.Gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.2-2'
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

You don’t need to include any extra libraries to enable view binding
remove kapt "androidx.lifecycle:lifecycle-compiler:2.2.0" and add
android {
..
buildFeatures {
viewBinding true
}
}
to build.gradle

Related

Issue with data binding with gradle 3.2.1

When i have updated android studios 3.2.0 to 3.2.1. I have use data binding, when run project show me error like this, if i am wrong please suggest me.
Could not find com.android.databinding:compiler:3.2.1.
Searched in the following locations:
file:/C:/Users/Taufiq/AppData/Local/Android/Sdk/extras/m2repository/com/android/databinding/compiler/3.2.1/compiler-3.2.1.pom
file:/C:/Users/Taufiq/AppData/Local/Android/Sdk/extras/m2repository/com/android/databinding/compiler/3.2.1/compiler-3.2.1.jar
file:/C:/Users/Taufiq/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/databinding/compiler/3.2.1/compiler-3.2.1.pom
file:/C:/Users/Taufiq/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/databinding/compiler/3.2.1/compiler-3.2.1.jar
file:/C:/Users/Taufiq/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/databinding/compiler/3.2.1/compiler-3.2.1.pom
file:/C:/Users/Taufiq/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/databinding/compiler/3.2.1/compiler-3.2.1.jar
https://repo.maven.apache.org/maven2/com/android/databinding/compiler/3.2.1/compiler-3.2.1.pom
https://repo.maven.apache.org/maven2/com/android/databinding/compiler/3.2.1/compiler-3.2.1.jar
https://jcenter.bintray.com/com/android/databinding/compiler/3.2.1/compiler-3.2.1.pom
https://jcenter.bintray.com/com/android/databinding/compiler/3.2.1/compiler-3.2.1.jar
https://dl.google.com/dl/android/maven2/com/android/databinding/compiler/3.2.1/compiler-3.2.1.jar
Required by:
project :app
project.gradle
buildscript {
ext{
kotlin_version = '1.2.71'
gradle_version = '3.2.1'
}
repositories {
jcenter()
maven { url 'https://maven.google.com' }
google()
}
dependencies {
classpath "com.android.tools.build:gradle:3.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenCentral()
jcenter()
maven { url 'https://maven.google.com' }
maven { url "https://jitpack.io" }
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app.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.taufik.kotlinbindingtest"
minSdkVersion 19
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'
}
}
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:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
kapt "com.android.databinding:compiler:$gradle_version"
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'
}
If i am wrong please suggest me.
I looked for many solution and finally i found that problem was in one of Dependencies, So I removed this kapt "com.android.databinding:compiler:$gradle_version" from app.gradle and project run succeffully.
The answer is pretty simple:
just add these lines in gradle app
//Data binding
dataBinding.enabled = true
and remove these two lines :
apply plugin: 'kotlin-kapt'
kapt "com.android.databinding:compiler:$gradle_version"
As of Android Studio 3.2, this kapt plugin is no longer required.
However, without this plug in, the error message in case of any error, while compiling is cryptic.
So, only option now it seems now is to downgrade your Gradle version to 3.1.4.
Thanks to article at http://mobiledevhub.com/2018/01/05/android-two-way-databinding/

Using Kotlin in a library module without using it in the app module

I'm trying to use Kotlin in a library module without using it in the app module. The app module only uses Java and does not use any Kotlin classes from the library. Gradle won't compile hoever:
Error:(2, 1) A problem occurred evaluating project ':<Library>'.
> Plugin with id 'kotlin-android' not found.
Changes I made to include Kotlin:
{library root} / build.gradle
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
...
}
allprojects {
repositories {
jcenter()
}
}
{library root} / {library module} / build.gradle
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
...
dependencies{
...
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
When I add the same to the app module, the project compiles without issue, but I'd like to avoid adding it in the app module because I'd like to use this library in multiple apps without making code changes to those apps
Gradle version used : 3.3
android gradle plugin version: 2.3.3
Edit: #Jushua's answer works, but it still requires to update the project root build.gradle. I was hoping for a solution where only the dependency on the library would have to be added to make the whole thing work.
I am able to do that without any problem.
build.gradle (Project)
buildscript {
ext.kotlin_version = "1.1.4"
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:2.3.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
build.gradle (app)
apply plugin: "com.android.application"
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
androidTestCompile("com.android.support.test.espresso:espresso-core:2.2.2", {
exclude group: "com.android.support", module: "support-annotations"
})
compile "com.android.support:appcompat-v7:26.0.1"
testCompile "junit:junit:4.12"
compile project(path: ":library")
}
build.gradle (library)
apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
minSdkVersion 17
targetSdkVersion 26
versionCode 13
versionName "1.1.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
androidTestCompile("com.android.support.test.espresso:espresso-core:2.2.2", {
exclude group: "com.android.support", module: "support-annotations"
})
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "com.android.support:appcompat-v7:26.0.1"
testCompile "junit:junit:4.12"
}
You just need to add in your module build:
buildscript {
// (Optional) ext.kotlin_version = '1.1.4-3'
repositories {
google()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
and you could either declare the kotlin_version variable in that specific build, or declaring it in the project root build file, since the kotlin version could be updated from other modules:
buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta3'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
You can add buildscript section with kotlin plugins only in your library:
buildscript {
ext.kotlin_version = '1.1.4-2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
And now you can include library to application, without modification of root build.gradle
compile project(path: ":library")

error: supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath

I can't compile my Android Kotlin project.
I have no idea what is this...
Gradle log:
error: supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class android.support.v7.app.AppCompatActivity, unresolved supertypes: SupportParentable
build.gradle (app)
buildscript {
ext.android_plugin_version = "2.3.3"
ext.kotlin_version = '1.1.2-5'
repositories {
maven { url 'https://maven.google.com' }
maven { url "https://jitpack.io" }
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:$android_plugin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
maven { url 'https://maven.google.com' }
maven { url "https://jitpack.io" }
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
def compat_version = '26.+'
def play_services_version = '11.0.1'
def firebase_version = '9.6.1'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.site.app"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["library" : "true"]
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "4g"
}
dataBinding {
enabled true
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
kapt {
generateStubs = true
correctErrorTypes = true
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
// android
compile 'com.android.support:multidex:1.0.1'
compile "com.android.support:appcompat-v7:${compat_version}"
compile "com.android.support:design:${compat_version}"
compile "com.android.support:cardview-v7:${compat_version}"
compile "com.android.support:recyclerview-v7:${compat_version}"
compile "com.android.support:gridlayout-v7:${compat_version}"
compile "com.google.android.gms:play-services:${play_services_version}"
compile "com.google.android.gms:play-services-ads:${play_services_version}"
compile "com.google.android.gms:play-services-maps:${play_services_version}"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.maps.android:android-maps-utils:0.4+'
kapt "com.android.databinding:compiler:$android_plugin_version"
// kotlin
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
In my case I had a library module with an abstract application class implementing Dagger's HasActivityInjector and an application module with a dependency to the library and its own (non-abstract) application class extending the base app class.
My Gradle dependencies were implementations, and therefore not accessible to the application module's application class (even though there were no imports there, otherwise the issue would be immediately obvious as you'd get a 'could not resolve' error. The fix was to replace dagger implementation dependencies with api, that makes them available to dependant modules as well.
I fixed it by changing the order of plugins call!
build.gradle
buildscript {
ext.android_plugin_version = '2.3.3'
ext.kotlin_version = '1.1.3-2'
repositories {
jcenter()
mavenCentral()
maven { url "https://maven.google.com" }
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
}
dependencies {
classpath "com.android.tools.build:gradle:$android_plugin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
classpath 'io.fabric.tools:gradle:1.+'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven { url "https://maven.google.com" }
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.sample.app"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
debug {
ext.alwaysUpdateBuildId = false
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "4g"
}
dataBinding {
enabled true
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
abortOnError false
disable 'InvalidPackage'
}
}
kapt {
generateStubs = true
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
// kotlin
kapt "com.android.databinding:compiler:$android_plugin_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
// android
compile 'com.android.support:multidex:1.0.1'
compile "com.android.support:appcompat-v7:${compat_version}"
compile "com.android.support:design:${compat_version}"
compile "com.android.support:cardview-v7:${compat_version}"
compile "com.android.support:recyclerview-v7:${compat_version}"
compile "com.android.support:gridlayout-v7:${compat_version}"
compile "com.android.support:support-vector-drawable:${compat_version}"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile "com.google.android.gms:play-services-ads:${play_services_version}"
compile "com.google.android.gms:play-services-maps:${play_services_version}"
compile "com.google.android.gms:play-services-gcm:${play_services_version}"
compile 'com.google.maps.android:android-maps-utils:0.4+'
// fabric
compile('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
transitive = true;
}
// logger
compile 'com.orhanobut:logger:2.1.1'
// dexter
compile 'com.karumi:dexter:4.1.0'
// firebase
compile "com.google.firebase:firebase-messaging:${firebase_version}"
// persistence
compile "android.arch.persistence.room:runtime:1.0.0-alpha3"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha3"
// facebook
compile 'com.facebook.android:facebook-android-sdk:4.+'
// retrofit
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
// gson
compile 'com.google.code.gson:gson:2.8.1'
// jobs
compile 'com.evernote:android-job:1.1.11'
// chart
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
// fresco
compile 'com.facebook.fresco:fresco:1.3.0'
// indicator
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
}
Before trying anything else, try:
Android Studio -> File -> Invalidate cache/restart
This worked for me.
For me the problem was child module not using AndroidX Activity. I guess the class names clashed.
Added this to resolve:
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
I solved my problem by deleting files related with dagger hilt from java(generated) and rebuild my project
(App)-----depends----(library)
In my case I did not change any dependencies configuration nor i change the order.
I had to copy a local pojo(model) jar file from the library module to App.
App is in kotlin
library is in java
Its a bug, I should not have pojo.jar in app and library
Clean Project and Rebuild it This works for me
Well in my case this error randomly occurs which usually occurs during execution through Android Studio.
The root cause was that My Activity class were extending some interfaces which was in another nested package:
package tv.activities
public class MainActivity implements MyListener {
}
package tv.activities.error
interface MyListener {
}
Hence it usually happens during execution but after second run it resolves automatically so no one bother to resolve it. Sometimes Android Studio fail to recognise that interface is accessible so there is no sense of showing error for the same:
Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
class tv.activities.MainActivity, unresolved supertypes: MyListener
Final Solution:
Making interface public resolves this issue permanently.
public interface MyListener {
}
Or refactor the package accessibility where AS doesn't get confuse
Make sure to add same dependencies in the project level as well which are added to the module
On my case I had to add the required dependency on my main module and compile the last version with:
android {
configurations.all {
resolutionStrategy.force "com.squareup.picasso:picasso:${picassoVersion}"
}
}
I was getting error for below lib in app level build.gradle
implementation 'com.google.firebase:firebase-iid:20.0.2'
So the solution is the order in project level build.gradle, So
before solving error the structure was
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
After Solving the error the struture is :
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
maven {
url "https://maven.google.com"
}
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven {
url "https://maven.google.com" // Google's Maven repository
}
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
By default it tries to download using google() as it comes first in the sequence but when we move maven on top of all then it creates the build again using maven and the build succeeds. Cheers :)
When setting up the crashlytics to my app, I used "recommended" dependency as well, as shown below. But this was the part causes error.
// Firebase Crashlytics
// (Recommended) Add the Google Analytics dependency.
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
Removing "analytics" line solved my problem.
// Firebase Crashlytics
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
Hope this helps someone else too,
best
I fixed this error upgrading others libraries.
My error showed when I added firebase=ads (from google adsmob).
So I found a conflict in my firebase-auth (16.0.5) and firebase ads (19.0.1).
Migrating firebase to 19.3.0 solved the problem.
In my case, I had removed an unused OnFragmentInteractionListener in a fragment:
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}
However, In my activity I had failed to remove a reference to this OnFragmentInteractionListener :
public class MainActivity extends AppCompatActivity implements
MyFragment.OnFragmentInteractionListener {
Strangely, instead of giving an error that indicated the OnFragmentInteractionListener was not found, I received the above "supertypes of the following classes cannot be resolved" with no reference to the classes.
In my case, I went to the project structure and updated all firebase dependencies to the latest and the highest. At the moment here are implementations with their versions:
implementation 'com.google.firebase:firebase-auth:19.3.1'
implementation 'com.google.firebase:firebase-database:19.3.1'
implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.google.firebase:firebase-analytics:17.4.3'
I deleted my build folder and restarted the project
app/build
Update your google play gradle version to the latest

Could not find method has() for arguments

I'm Getting Following error while building my Android project.
Error:Could not find method has() for arguments [release] on project ':volley' of type org.gradle.api.Project.
Following are my build.gradle files
Project Level:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App level:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
//apply plugin: 'realm-android'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.haha.sampleappid"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.google.firebase:firebase-messaging:9.4.0'
compile 'com.google.firebase:firebase-auth:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile project(':volley') //TODO:add as gradle dependency which will be while enabling proguard
compile('com.digits.sdk.android:digits:1.11.1#aar') {
transitive = true;
}
compile "com.android.support:recyclerview-v7:23.0.1"
compile 'com.google.firebase:firebase-ads:9.4.0'
}
apply plugin: 'com.google.gms.google-services'
volley/build.gradle
// NOTE: The only changes that belong in this file are the definitions
// of tool versions (gradle plugin, compile SDK, build tools), so that
// Volley can be built via gradle as a standalone project.
//
// Any other changes to the build config belong in rules.gradle, which
// is used by projects that depend on Volley but define their own
// tools versions across all dependencies to ensure a consistent build.
//
// Most users should just add this line to settings.gradle:
// include(":volley")
//
// If you have a more complicated Gradle setup you can choose to use
// this instead:
// include(":volley")
// project(':volley').buildFileName = 'rules.gradle'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
}
apply plugin: 'com.android.library'
repositories {
jcenter()
}
android {
compileSdkVersion 22
buildToolsVersion = '22.0.1'
}
apply from: 'rules.gradle'
apply from: 'bintray.gradle'
Has anyone run into a similar problem before?
Advice would be much appreciated.
open the Volley's bintray.gradle file and find the below :
publish = project.has("release")
and change the line to as below
publish = project.hasProperty("release")
this resolves the issue in most of the cases.

Error:(3, 0) Cause: org/apache/commons/lang3/StringUtils

I get the following error
Error:(3, 0) Cause: org/apache/commons/lang3/StringUtils
when I try to add data binding in my Android project.
My dependencies include :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha7'
classpath 'me.tatarka:gradle-retrolambda:3.2.2'
classpath 'com.android.databinding:dataBinder:1.0-rc1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My gradle wrapper is : distributionUrl=https://services.gradle.org/distributions/gradle-2.2.1-all.zip
My gradle file :
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.android.databinding'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.quizviz.workbook.myworkbook"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'io.reactivex:rxandroid:1.1.0'
compile 'io.reactivex:rxjava:1.1.0'
compile 'com.jakewharton.rxbinding:rxbinding:0.2.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-jackson:2.0.0-beta3'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta3'
compile 'com.squareup.okhttp3:okhttp:3.0.1'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.0.1'
}
It took me a while to notice this problem is caused by google updating the way to use data binding library. You can see more information from here:
http://developer.android.com/tools/data-binding/guide.html.
You can just remove these two lines of code:
apply plugin: 'com.android.databinding'
And this one in buildscript's dependencies:
classpath 'com.android.databinding:dataBinder:1.0-rc1'
Then add the dataBinding section to your build.gradle like this.
buildscript {
...
}
android {
...
dataBinding {
enabled = true
}
...
}
dependencies {
...
}
Here you go. This works for me :).

Categories

Resources