classNotFoundException while accessing the aar file's classes in Android Studio - java

I created an aar file from an module and added it to my project it got added successfully but whenever I am trying to run my app then every time it is getting crashed saying classNotFoundException.
I tried to add dependencies in my module using implementation, api and compile (deprecated now) but still getting the same issue.
I hosted my aar file at Maven and tried to add that dependency in my project but still no luck and getting the same error every time.
There is a work around for the same I can add the those dependencies into my project which I added into my module but I do not want to that.
If I add my project as dependencies then it works fine but I do not want to that also as the module I am working on will be used by multiple clients and I do not want to share my source code with everyone.
I am using the following:
Android Studio 3.5.3
Android Gradle Plugin version 3.5.3
Gradle version 5.4.1
Min SDK Version 21, compile SDK version 29
JDK 8
Is there anything I am doing wrong or I am missing, any help will be appreciated.
Edit 1
I am not using proguard that is disabled.

It is related to proguard, try adding a rule to keep the class in proguard-rules.pro file
-keep class com.app.package.** { *; }
-dontwarn com.app.package.**
replace 'com.app.package ' with your package (where the Notfound class exist)

Related

The project uses Gradle 2.10 which is incompatible with Android Studio 2020.3

While learning android studio from udacity they asked me to download a project; I did so but while I was importing it to android studio I got an error message:
The project uses Gradle 2.10 which is incompatible with Android Studio 2020.3.
Why did I get this error?
If you did not figure this out yet, I am just starting the same project too. I changed the classpath like above. I then found a website to use the latest version of gradle and the plugin. It says "You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or by editing the Gradle distribution reference in the gradle/wrapper/gradle-wrapper.properties file." I did the first one.
Then, I got errors for both build.gradle files in the project and app version. I get this error: Could not find com.android.tools.build:gradle:7.0.3
If you get this error, click the link "Add google Maven repository and sync project". Then you have to click "Do refactor".
Now you come across another error in one of the build.grade files. This stackoverflow link will tell you: Gradle - Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0]
Finally, replace testCompile with testImplementation and then you should get BUILD SUCCESSFUL.
The project's Gradle version you're trying to clone is outdated. Change it based on your android studio version.
on your build.gradle(Project) change the version and sync
classpath "com.android.tools.build:gradle:4.1.2"
Got the solution :)
In gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
In build.gradle project level:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
In build.gradle module level:
Replace all "compile" with "Implementation" and do other suggested version updated and you are done here :)
Hope this works for you, if yes just press that up button :)
If not getting any solution, the best you can do is copy the "app" folder of your project(using file explorer) and paste it in a newly created project(should be of same name as of your project), in that way you'll get already synced gradle and newly created version of your app.
Because, every important thing in your project is present in its app folder and when you create a new project with same name and copy app folder from your older version of your project, you will have a newer version of your project with all same resources.
Note: You can't move through branches and other commits
I saw this issue several times with Android studio. Below trick worked me the best.
Android Studio suggests to upgrade to newer version, please upgrade it and let it sync
Mostly you would see error message again
Now, Go to File -> Invalidate Caches/Restart
It should work now
If it shows same error then I don't know what to do.
If it shows different error then repeat from step 1 to 3 for new error.
Hope, it helps some..

IntelliJIdea: Unable to load class 'org.gradle.api.artifacts.result.ComponentArtifactsResult'

When configuring project with Gradle I recieve:
Unable to load class 'org.gradle.api.artifacts.result.ComponentArtifactsResult'.
This is an unexpected error. Please file a bug containing the idea.log file.
I have same error when using either local gradle distribution option: C:/Users/user/Downloads/gradle-1.12-bin/gradle-1.12
or gradle 'wrapper' task configuration file with url: distributionUrl=https://services.gradle.org/distributions/gradle-1.12-bin.zip.
Also tried to delete .gradle folder and configure project again and use default gradle wrapper.
So, there're many examples to solve it using Android Studio but unfortunatelly none for IDEA. Is there any way to resolve this problem?
EDIT: So, it was only part of trables with Gradle. The true problem was in encache library version. It was so in my gradle.build:
module: "ehcache", version: "2.10.4"
The decision was in changing Gradle version to 4.7 and removing encache version like this:
module: "ehcache"
Now it works fine.

How to add commons-math library in Android Studio

I am trying to import common-math library to my Android Studio project. I placed the file commons-math3-3.6.1.jar file in libs folder and in the gradle file I have this line:
compile 'commons-math3-3.6.1.jar'
But I get this error: `
Error:(32, 0) Supplied String module notation
'commons-math3-3.6.1.jar' is invalid. Example notations:
'org.gradle:gradle-core:2.2',
'org.mockito:mockito-core:1.9.5:javadoc'.
Can anyone tell me what I have to do?
Is there a reason you need to use the jar file? You can get the file directly from Maven repository using something like this:
compile 'org.apache.commons:commons-math3:3.6.1'
Available on both JCenter and MavenCentral.
in Android view open Gradle Scripts - build.gradle and add this to dependencies:
implementation 'org.apache.commons:commons-math3:3.6.1'
You can also check their websites if newer version isn't available list of latest versions

Java library that depends on android.os results in NoClassDefFoundError when used

I've created a java annotation processor in a project (which I'll call JavaLibrary) that makes use of android.os.Bundle. As such, the project has the following line in its gradle.build dependencies:
compile 'com.google.android:android:4.1.1.4'
In gradle.build, sourceCompatibility and targetCompatibility are both set to version 1.6 and this project compiles just fine on its own.
I have also created an Android Library project (which I'll call AndroidLibrary) that depends on JavaLibrary. I'm expecting JavaLibrary to process some annotations used in AndroidLibrary and generate some code.
However, when I try to compile AndroidLibrary, I get the following error:
java.lang.NoClassDefFoundError: android/os/Bundle
The stack trace shows the line where the android.os.Bundle is referenced in JavaLibrary.
Why is this happening and how do I get these two projects to compile together?
I'm not sure with gradle parts. The Android OS jars we build against are just API stubs and should not be exported since they are "provided" by the device.
To use Android classes in Java projects, you can copy the Java source files you need into your Java project so long as they (and their dependencies) don't reference native or internal code.
Not sure why you need a bundle in there, but here's a link to GrepCode's copy of it's source:
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2.1_r1/android/os/Bundle.java

Dalvik VM error: Exception found "Javax.xml.namespace.QName.class"

This isn't intended to be a question. Rather, an observation which is a common problem found in Android when you use external APIs for development and android.jar isn't duplicated into your project!
After searching through various forums, Google and stackoverflow, I seem to get a solution by myself and thought of sharing it.
Whenever you are linking external libraries, better link it by creating a /lib folder and dump those .jars there(means to COPY the files and NOT linking them). Link them using Eclipse -> Build Properties -> Configure Build path -> Library tab -> Add external Jars. Add the required .jars saved in /lib folder in this. (Note that, the jar included as a "Referenced Library" in Eclipse will disappear in /lib folder! But, not to worry as proper linking has happened. Another note is to check that the /lib jar that was referenced should NOT be visible in Libraries tab of Build Properties as it will be inherited.)
Another major problem was when Google APIs are being used. Specially the ones, which use some core library functions of java/javax. Be very careful of this. The error is that, the DalvikVM tries to link these but fails as there is a duplication found and is unable to decide which one to refer to. Below is the error.
Dx trouble processing "javax/xml/namespace/QName.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*) when not building a core library.
In such cases, what I have observed is that, this class is used in xpp3-1.1.4c.jar. If you've copied this into your /lib folder, PLEASE REMOVE IT. Then clean the project, and give a fresh build. And the ship sails smoothly thereafter.
Do this for other referenced .jars if such duplication exists.
Cheers!
This worked for me. I'm using maven, and the xpp3-1.1.4c dependency shows up under "Maven Dependencies"; I had to exclude it using (right click the dependency) Maven-> "Exclude Maven Artifact...". Thanks a bunch -- this was really obscure.
This error show only when you trying to generate signed APK.
There are 2 ways to fix this.
1. As commented Amira Elsayed Ismail in this post this
we should revert to gradle 2.3.3.
To do this you should also download Android Studio 2.3.3 because studio 3.0.1 require gradle plugin 3.0+
This was the first solution. But reverting Android Studio and gradle plugins is a painful solution.
2. Resolve all dependency conflicts.
When i revert gradle, Studio 2.3.3 showed we interested warnings(i do not know why studio 3.0.1 don't show dependency conflict warnings)
Warning:WARNING: Dependency xpp3:xpp3:1.1.4c is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.3 is ignored for debug as it may be conflicting with the internal version provided by Android.
So these dependencies are ignored for debug but NOT FOR RELEASE.
I fixed this by excluding these dependencies.
configurations {
all*.exclude group: 'xpp3', module: ['xpp3' ,'httpclient']
}
After this, i successfully generated signed APK using gradle 3.0.1.(without reverting).

Categories