I am building a library in Android Studio which has multiple Gradle dependencies such as the estimote and firebase sdk. When I export the library as an aar and then import it to a sample project, I get a run time error:
E/UncaughtException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/estimote/sdk/BeaconManager;
at com.mgenio.sdk.BeaconSDK.init(BeaconSDK.java:87)
at com.mgenio.sdk.BeaconSDK.checkSDK(BeaconSDK.java:214)
at com.mgenio.sdk.BeaconSDK.access$800(BeaconSDK.java:33)
at com.mgenio.sdk.BeaconSDK$3.onResponse(BeaconSDK.java:186)
at com.mgenio.sdk.BeaconSDK$3.onResponse(BeaconSDK.java:182)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.estimote.sdk.BeaconManager" on path: DexPathList[[zip file "/data/app/com.mgenio.smartscansample-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mgenio.smartscansample-1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
Is there a special way to export my aar library so it includes these external dependencies? Thanks!
I had a similar issue some months ago, if you're publishing your library in a repository, then you have to add an xml or another kind of file that contains the dependencies your library have.
And if you need yo use any class of those dependencies, when you compile your library in the gradle file in your app module, you have to add transitive=true to have access to this classes or resources like this
compile('mx.segundamano.doubleseekbarview'){
transitive=true
}
EDIT
If you're publishing to Bintray - Maven repository, add this lines to your gradle file at the same level where your bintray configuration is
task generateSourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier 'sources'
}
artifacts {
archives generateSourcesJar
}
Is there a special way to export my aar library so it includes these external dependencies?
No
Exept you deploy your aar into a maven or ivy repository.
These aar dependency have some inbuild functionality in itself such as ic-launcher icon , image,logo, animation and much more.
Dhamija Dependency is one of them. such as :-
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.0#aar'
compile 'com.daimajia.androidanimations:library:1.0.8#aar
but you can use a best commercial dependency inside aar Remove above dependency and use this :
implementation 'com.airbnb.android:lottie:2.5.4'
hope this will resolve your issue !
You just add the same dependencies to your sample project and let Gradle take care of it.
Related
Currently I need to build an Android library .aar file. In the library have network request so that I have to add Retrofit as library's dependencies.
My library build.gradle file look like:
dependencies {
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
}
But when using aar file by
compile(name:'sdk-release', ext:'aar'){transitive=true}
It's throw exception:
java.lang.NoClassDefFoundError
After research, I figured out that the Problem is "transitive dependencies".
Do we have any solution to fix this problem?
Many thanks.
I have an Android project, inside I have a library module, my project works fine, compile the project I get the .aar included in a test project and everything ok.
Now,I have added in my library module a Activity that extends Application, Y Added this class in the manifiest.xml of the library
<application
android:allowBackup="true"
android:label="#string/app_name"
android:name=".MyActivityExtendsApplications"
When I test the project it works perfect, but when I take the .aar and test it on other project fails. The problem is that it does not find the activity extend Application ... I have decompiled the aar and I see that everything is correct, all class are inside the folder
The error is
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mylibrary.MyActivityExtendsApplications" on path: DexPathList[[zip file "/data/app/com.myapplication-1/base.apk"],nativeLibraryDirectories=[/data/app/com.myapplication-1/lib/arm, /vendor/lib, /system/lib]]
Suppressed: java.lang.ClassNotFoundException: com.mylibrary.MyActivityExtendsApplications
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
I adding grandle dependency to library .aar In all cases in the same way
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:24.2.1'
compile 'com.android.support:design:24.2.1'
testCompile 'junit:junit:4.12'
compile 'mylibrary-debug.mylibrary-debug#aar'
}
repositories{
flatDir{
dirs 'libs'
}
}
I check merged manifest in my test Project and the activity is there
application
android:name="com.mylibrary.MyActivityExtendsApplications"
android:allowBackup="true"
And I can import this Activity in my test Project and see the code
And I added mylibrary in libs folder.
When I remove the activity MyActivityExtendsApplications, my library works fine.
The issue may be the the Android Beacon Library aar files are missing when you generate your library aar, and the exception description is simply misleading. I don't think classes from aar files are automatically merged when generating a new aar file. You might check to see if these files (like Beacon.class) are missing from your aar.
If this is indeed the problem, there are two possible solutions:
In your application, reference both your library aar file and the Android Beacon Library aar file.
Merge the classes from the first aar file into your new aar file. I have done this before with rather a rather inelegant shell script that I am happy to share, but there may be a better way to accomplish the same thing.
I am using android's data binding library for views in a library project
i have added the following line in my root gradle file
classpath 'com.android.databinding:dataBinder:1.0-rc1'
and have enabled the dataBinding as given below in module's gradle file
apply plugin: 'com.android.databinding'
...
...
android {
....
dataBinding {
enabled = true
}
}
i have enabled the multiDex in my library project
as well as in the host app which is using this library
but i get this stack trace of error while launching the library's activity
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/databinding/DataBinderMapper;
at android.databinding.DataBindingUtil.<clinit>(DataBindingUtil.java:31)
at sdk.ui.activities.MyActivity.onCreate(MyActivity.java:76)
at android.app.Activity.performCreate(Activity.java:6280)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1116)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2647)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1502)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5763)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.databinding.DataBinderMapper" on path: DexPathList[[zip file "/data/app/testApp.dev-1/base.apk"],nativeLibraryDirectories=[/data/app/testApp.dev-1/lib/arm64, /data/app/testApp.dev-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.databinding.DataBindingUtil.<clinit>(DataBindingUtil.java:31)
at sdk.ui.activities.MyActivity.onCreate(MyActivity.java:76)
at android.app.Activity.performCreate(Activity.java:6280)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1116)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2647)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1502)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5763)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
Suppressed: java.lang.ClassNotFoundException: android.databinding.DataBinderMapper
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 15 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
Make sure that ALL your modules that use DataBinding have it enabled. This was the reason I got that exception.
android {
....
dataBinding {
enabled = true
}
}
finally i was able to solve this issue.
It seems there was a conflict between apt version of the app and library modules.
upgraded the apt version in the app to
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
Besides adding the following to build.gradle:
android {
dataBinding {
enabled = true
}
}
I also have to add the following dependency:
dependencies {
kapt 'com.android.databinding:compiler:3.1.4'
}
Best guess. Get rid of android-apt
And if there are libraries using apt
Instead of apt 'lt.mdm.sdd:myLib:1.5.1' use
annotationProcessor 'lt.mdm.sdd:myLib:1.5.1'.
I'm not sure if this will help you, and i have no idea if library it self should be changed.
It helped me (i was using androidannotations.org older version with apt) at least.
Update
And i have no idea why you apply plugin: 'com.android.databinding'? It works without it as well.
I had the same problem after performing the migration androdx. I tried all the above methods but not resolved. I suddenly found that I used
com.android.tools.build:gradle version is 3.3. I update it to 3.5. Problem is solved.
project build.gradle:
classpath 'com.android.tools.build:gradle:3.3.0'
Update to
classpath 'com.android.tools.build:gradle:3.5.0'
Redo the migration.
classpath 'com.android.databinding:dataBinder:1.0-rc1'
apply plugin: 'com.android.databinding'
Remove that lib. from gradle.
I had the same problem, but I solved it removing
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
from the global build.gradle and removing
apply plugin: 'android-apt'
from the local build.gradle, then it worked like a charm.
It seems it was a mixed problem with Butterknife too. Pretty weird.
The new way of adding DataBinding is by adding on the build.gradle of all your modules:
android {
...
buildFeatures {
dataBinding true
}
}
Don't forget to add also the kotlin-kapt plugin at the top:
plugins {
...
id 'kotlin-kapt'
}
Get inspiration from #Bolein95 say.Because it depend on a library that does not support androidx(no setting databinding=true),Written by a colleague who has left.I copy a few necessary files from his github repo, it work!
I am using okhttp3 with glide so I have added the integration part as well.
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.github.bumptech.glide:okhttp-integration:1.4.0#aar'
I have even enabled multidex support using
compile 'com.android.support:multidex:1.0.1'
and adding this to application class
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(base);
}
Here is full stack trace -
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/okhttp/OkHttpClient;
at com.bumptech.glide.integration.okhttp.OkHttpUrlLoader$Factory.getInternalClient(OkHttpUrlLoader.java:30)
at com.bumptech.glide.integration.okhttp.OkHttpUrlLoader$Factory.<init>(OkHttpUrlLoader.java:41)
at com.bumptech.glide.integration.okhttp.OkHttpGlideModule.registerComponents(OkHttpGlideModule.java:31)
at com.bumptech.glide.Glide.get(Glide.java:157)
at com.bumptech.glide.RequestManager.<init>(RequestManager.java:62)
at com.bumptech.glide.RequestManager.<init>(RequestManager.java:53)
at com.bumptech.glide.manager.RequestManagerRetriever.supportFragmentGet(RequestManagerRetriever.java:198)
at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:104)
at com.bumptech.glide.Glide.with(Glide.java:644)
at com.skcsllp.mutterfly.activities.EditProfileActivity.onCreate(EditProfileActivity.java:76)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.squareup.okhttp.OkHttpClient" on path: DexPathList[[dex file
"/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-support-annotations-23.2.1_711eea7d990a3279fc66c06b239bf29196aabc02-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_9-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_8-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_7-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_6-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_5-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_4-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_3-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_2-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_1-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-slice_0-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-okio-1.6.0_4cb2265fa47e13dbef896857be4ee851d4d21b93-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-okhttp-3.2.0_c46370073bf914e884c23455554d5f56e9b15f17-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-internal_impl-23.2.1_945649fcb49395f2024bfee914abcd2b33619e3f-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-gson-2.2.4_d0ce76b63ce905fbab3c5d385c8e1b8692010f19-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-glide-3.6.1_362f6061e938ba7d3e28c67a4832a9a19bdf24aa-classes.dex",
dex file "/data/data/com.skcsllp.mutterfly.debug/files/instant-run/dex/slice-com.google.android.gms-play-services-gcm-7.8.0_defd878a1ea68768e6e678ca0946f67a973b8929-classes.dex",
this is config for build
productFlavors {
// Define separate dev and prod product flavors.
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 15
}
}
I could not figure out what's wrong with dex process.
EDIT
Everything works great if i simply remove the integration part from the build.gradle
compile 'com.github.bumptech.glide:okhttp-integration:1.4.0#aar'
No need for multidex unless you have too many methods.
Decide if you're using okhttp (v2) or okhttp3 and update your code accordingly:
compile 'com.github.bumptech.glide:okhttp-integration:1.4.0#aar'
compile 'com.squareup.okhttp:okhttp:2.7.5'
or
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0#aar'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
Read https://github.com/bumptech/glide/wiki/Integration-Libraries for more details.
(Source: https://github.com/bumptech/glide/issues/1158#issuecomment-215007390)
I'm using the Open Mobile API (SEEK API) in my project by adding the jar file to my gradle build:
dependencies {compile files('libs/org.simalliance.openmobileapi.jar')}
it gives me this exception:
java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:222)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:215)
at dalvik.system.DexPathList.findClass(DexPathList.java:322)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
My understanding is I need to include the jar in compile process but exclude it in the linking and don't export it to my APK. this is normally done with a simple checkbox in eclipse, but I can't find a way to do it with gradle.
any help is appreciated.
To not export your .jar THIS is maybe helpful. (reads well)
Additionally:
Try this to get rid of the error:
Go to modules -> dependencies, then set scope of the lib to 'Provided'.
here is my source