I have been stuck for the past 2 days now. I want to import my own aar in one of my sample apps and then use it. I can not access the classes inside the aar and get a java.lang.NoClassDefFoundError error.
Now since this is a common problem, I have tried the below so far,after reading each and every related question:
1) Importing the aar by going to : File -> New-> New Module -> Import .JAR/.AAR
and then adding compile project(':Name-Of-Your-Project') to the gradle.
2) Using the maven plugin and pushing the aar to the local maven repo by using gradle install and then reffering to the local repo aar in my gradle.
compile ('com.rsa.mobile.sdk.android:authsdk:3.6.0-SNAPSHOT:debug#aar'){
// transitive=true
}
Note: If I uncomment the transitive=true, i get the below exception while installing the application:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
3) Rebuilding and cleaning the project as suggested in a lot of answers.
4) The only one thing which didnt work out was by putting the aar in a directory and then reffering it like compile(name:'Name-Of-Your-Project', ext:'aar') , after adding
flatDir {
dirs 'libs'
}
to the repo.
I dont think the 4th point should matter as the correct way now is as mentioned in point 1 above, but just wanted to put it out.
Can someone please help. It looks like a trivial issue but I have already wasted around 2 days.
Looking at the exception the below code can solve the problem. Add it in the application gradle.
android {
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
dexOptions {
// FOR GC overhead
incremental true
javaMaxHeapSize "4g"
}
}
Related
Im getting the above error trying to create a release build of my app. When doing a debug build everything is running fine.
My project has a structure as follows
app (contains databinding)
video sdk (contains data binding)
another sdk (contains data binding)
Im thinking it finds multiple databinding instances which makes the above error but im not really sure how to circumvent this.
What also weird is that the app does compile when clicking run in Android studio but when trying to build from terminal its not compiling
Posting few of workarounds here
./gradlew clean
Exclude duplicates as message Program type already present means there is a naming conflict.
configurations {
compile.exclude group: 'androidx.databinding', module: 'databinding'
}
Then do sync, clean & rebuild.
I am not sure but tried to create a separate module for databinding gradle and add that module into all current modules (app, video sdk, another sdk)
Module core (Gradle with "api"):
api 'com.github.bumptech.glide:glide:4.9.0'
kapt 'com.github.bumptech.glide:compiler:4.9.0'
App module and other SDKs modules will use that core module.
implementation project(path: ':core')
Hope it will help.
I faced this error and spent almost 2 days in figuring out what was causing this error. Eventually, I found out that one of my transitive SDK, which used Kotlin, did not have the following in its Gradle file.
kotlinOptions kotlin_options = {
jvmTarget = "1.8"
}
After adding this, I was able to resolve the error.
Please try this, I am not sure but sometime release apk having problem of conflict ion
Add multiDexEnabled true in app gradle file.
Hope this will help!
I have to create an application that makes extensive use of charts.
Reading the web I chose achartengine that seems to have everything I need.
I downloaded the jar file, I plugged in the libs folder, I selected "add to library" and I lunch the gradlew clean.
Result in the sources where I do the import of org.achartengine.xxxx I always returned the error that fails to resolve symbols .
Do you have suggestions?
Thank you
Andrea
I am able to use this library in my Android Studio project, this topic explains how to add AChartEngine repo to your project.
What I did:
Added following to project-wide build.gradle (one from the project root):
allprojects {
repositories {
...
maven {
url "https://repository-achartengine.forge.cloudbees.com/snapshot/"
}
}
}
For every module that uses the library, add this to its build.gradle (you may put this to the top-level build.gradle if it should be included in all modules):
dependencies {
...
compile group: 'org.achartengine', name: 'achartengine', version: '1.2.0'
}
Now I can use the library in the project, I see the classes in code assist popups and build runs as succeeds.
It seems like the new version (1.2.0) is not available for download anymore in the http://www.achartengine.org/ site. and that's why the gradle/maven method doesn't work (or the snapshot file was removed).
I succeeded using and adding it to my project by downloading the jar file from here:
https://github.com/ddanny/achartengine/files/460139/achartengine-1.2.0.zip
Situation is that I in my project use library A. I also import external library which also has itself a library A. So as you can assume, when I try to compile, I receive Multiple DEX files define error which means that there are duplications.
However, If I remove my library from the project, I cannot use its provided methods. And I cannot find how can I remove that library from the module.
Any suggestions?
You should be able to exclude it like this:
compile('library:1.0.0') {
exclude group: 'something', module: 'something'
}
So do this on the external library for all the things you're using that's causing a problem.
From here: https://discuss.gradle.org/t/how-to-exclude-transitive-dependency/2119/2
define multiDexEnable True in your build.gradle(app)
defaultConfig {
multiDexEnabled true
}
and also define in dependency in same build.gradle(app)
compile 'com.android.support:multidex:1.0.1'
Thank you guys for your suggestions.
I didn't want to do as Michael suggested because I believe it is kind of useless (having multiple libraries with same purpose) (already knew this trick).
I have tried Ядм Жцмдшдт answer, but couldn't succeed in compiling code completely. I have received various errors.
In the end I have solved my own issue. What I did:
Remove library from my main app libs folder. Remove dependancies if any in Android Studio (File -> Project Structure -> Dependencies (On module app) -> remove if any regarding your library.
Clean project in Android Studio (Build -> Clean Project).
Go to the module where my library A is. Go to that module build.gradle file and add following line in the dependencies cluster
compile files('libs/libraryA.jar')
Sync code and enjoy results.
TLDR
I didn't have libraryA compiled in my external module but it threw me duplication error, that's where I was confused. By removing it from my main project and adding it to my module's compilations list solved the problem.
I'm working on an Android application with databinding but I've always next error:
Error: Package my.package.databinding does not exist.
Here is my build.gradle on project level:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I've also enabled binding in the build.gradle file on module level.
Now my question is, why occurs this error and how could I solve it?
This problem occurs usually if your project does not compile. Android databinding should generate code in the named package, but it can't do that if the project doesn't compile in the first place.
To solve this, bring your project to a point where it compiles. If necessary, turn databinding off for this.
check out your xml files and comment any #{} you have used unless you actually have your data ready at hand. With no data, you'll bump into this error again and again and again.
I came across this issue in a project of 4 modules in Android Studio 2.3, it is what #F43nd1r indicated, but want to document what I did to resolve this in my case.
One of the 4 modules had an older Android Support library in in the Gradle file for it, while the other 3 were current. This is what prevented the project from compiling properly and causing the databinding error.
The difficult part was that you don't know about this unless you open each build.gradle file and see if there is an error displayed. It did NOT show an error for it on compile.
Effectively I updated this area to the newer version number to match the other 3 module build.gradle files.
dependencies {
...
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:support-v4:25.2.0'
compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
...
}
To see the error, just edit these lines of code in the app's build.gradle:
dataBinding {
enabled = false
}
In this way, the last error in your build console is the actual error. Because from the first to the penultimate error, they are all related to the non-generation of the data binding classes, precisely because we have disabled it.
Once you find the error you will enter again :
dataBinding {
enabled = true
}
dataBinding {
enabled = true
}
enabled the data binding in app build.gradle file. its worked
Based on similar issues on SO, the reasons may not be related to android data binding, and instead due to incorrectly calling variables as in this issue or some other factors like in this other issue. You should provide more details if none of these links helps.
For me doesn't work anything except one: Renamed XML binding class
What I tried before:
off/on viewBinding
renaming folders
reinstalling modules
renaming modules
After deleting the build folder for the project and submodules, making, rebuilding, etc etc etc, the only thing that worked for me was:
create a new layout
I think there's something in the generator that gets messed up and that flushes it (totally guessing here)
Remember to add
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
...
buildFeatures {
viewBinding true
dataBinding true
}
}
I'm running into a collection of gradle problems in setting up a multi-module project. I'm trying to produce an AAR that contains an SDK for our customers use. I'm also trying to produce a sample application that uses that AAR both as a development platform internally and as an example for our customers of how to use the platform.
settings.gradle:
include :sdk
include :SampleApplication
build.gradle:
...
// copy the AAR produced by the SDK into the SampleApplication
task import_aar(type: Copy) {
dependsOn ":sdk:build"
from(new File(project(':sdk').getBuildDir(), 'outputs/aar')) {
include '*-release.aar'
rename '(.*)-release.aar', '$1-v1.0.0.aar'
}
into new File(project(':SampleApplication').projectDir, 'aars')
}
...
SampleApplication/build.gradle:
...
repositories {
...
flatDir {
dirs 'aars'
}
}
...
dependencies {
...
// This causes gradle to fail if the AAR hasn't been copied yet
compile 'com.moxiesoft.netagent:moxieMobileSDK:+#aar'
compile project(':moxieMobileSDK')
...
}
So the biggest problem that I'm having right now is getting the import_aar task to run before the compileDebug/ReleaseSources tasks. I've tried adding explicit dependencies to the compile tasks, but I'm apparently not finding the right way to do it.
I've tried putting this in SampleApplication/settings.gradle:
tasks['compileReleaseSources'].dependsOn(':import_aar')
but gradle fails because there's no compileReleaseSources task, even though gradle :SampleApplication:tasks shows one.
I also tried putting similar stuff in settings.gradle, but it also failed with an error that the task compileReleaseSources didn't exist.
I did have limited success by putting this in my SampleApplication/settings.gradle:
tasks['build'].dependsOn(':import_aar')
But that only has the correct affect if I use "gradle build", which doesn't happen if I'm debugging or running from Android Studio.
I was finally able to get this to work by putting the dependsOn on the preBuild task, but I'm still not particularly happy with the solution, because:
It requires me to have the aar in place before gradle runs, which
means I wind up putting the .aar into git, which isn't a
particularly good idea.
I'd rather not have the AAR generation leaking into the
SampleApplication/build.gradle file, since that's intended for
customer usage.
Is there a better way of handling the problem in general?
I also had problem adding a dependency to compileReleaseSources task and described here a solution that worked for me. In short, the dependency need to be added in tasks.whenTaskAdded closure.