Android, ClassNotFoundException when using the "provided project" OR IllegalArgumentException: already added when using the "compilation project",

Im getting a very unusual, ClassNotFoundException when starting the application for my com.xyz.sample.QuickSampleApplication class when using the "provided project" in the gradle script dependencies OR another error Unsaught conversion error: java.lang.IllegalArgumentException: already added: when using the "compilation project "in the gradle dependencies.

Actual error:

E/AndroidRuntime(17749): java.lang.RuntimeException: Unable to instantiate application com.xyz.sample.QuickSampleApplication: java.lang.ClassNotFoundException: Didn't find class "com.xyz.sample.QuickSampleApplication" on path: DexPathList[[zip file "/data/app/com.uei.sample.library-2.apk"],nativeLibraryDirectories=[/data/app- lib/com.uei.sample.library-2, /vendor/lib, /system/lib]] 

Project explanation:

com.xyz.sample.QuickSampleApplication is used by com.xyz.sample.QuickSampleActivity , and both classes are in the same package com.xyz.Sample .

Com.xyz.sample.QuickSampleApplication uses a JAR called 'quicksdklibrary , which I included as the' provided dependency 'in gradle, see the gradle fragment below:

 dependencies { provided project(':quicksdklibrary') //OR provided fileTree(dir: 'libs/MyExternalLibs', include: '*.jar') compile 'com.android.support:appcompat-v7:21.0.0' } 

The JAR is actually resolved in the IDE, it builds without errors, and the internal JARs classes are visible to my application classes such as my:

com.xyz.sample.QuickSampleApplication OR com.xyz.sample.QuickSampleActivity.

How com.xyz.sample.QuickSampleApplication AND com.xyz.sample.QuickSampleActivity are declared / spelled correctly in AndroidManifest.xml:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xyz.sample.library" android:versionCode="1" android:versionName="1.0.002"> <uses-sdk android:minSdkVersion="19" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <application android:icon="@drawable/icon" android:label="@string/app_name" android:name="com.xyz.sample.QuickSampleApplication"> <activity android:name="com.xyz.sample.QuickSampleActivity" android:screenOrientation="portrait" android:label="@string/app_name" android:launchMode="singleTask"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

When I opened the actual generated .apk file, I found that my com.xyz classes ... were not packaged in .apk, why ???

I tried to include the source explicitly in the dependency tag:

 compile fileTree(dir: 'src/main/java', include: ['*']) 

OR

 compile fileTree(dir: 'src/main/java/com/xyz', include: ['*']) 

OR

 compile fileTree(dir: 'src/main/java/com/xyz', include: ['*.java']) 

OR

  compile fileTree(dir: 'src/main/java', include: ['*.java']) 

OR

  compile file(libs/quicksdklibrary.jar) 

Based on comments, we also tried to use sourceSets tags:

OR using the sourceSets tag:

 sourceSets { main{ java { java.srcDirs 'src/main/java' } } } 

OR

  sourceSets { main{ java { java.srcDirs 'src/main/java/com/xyz' } } } 

However, the generated ".apk" still does not contain com.xyz class packages ...

Last update of the problem, see below:

Alternative try # 1:

When I use this tag in my gradle

 dependencies { compile 'com.android.support:appcompat-v7:23.0.1' provided project(':quicksdklibrary') } 

Then I get a ClassNotFoundException (checking apk and class classes.dex confirms that my quicksdklibrary classes are not included) , however, when I use:

 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) // OR compile files(libs/:quicksdklibrary.jar) // OR compile project(':quicksdklibrary') compile 'com.android.support:appcompat-v7:23.0.1' } 

Then I get this other error, which does not even allow me to deploy / install apk:

: application: preDexDebug

 Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/xyz/ace/ACEUtils$Creator; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/xyz/ace/AEUtils; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/xyz/ace/AEngine; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/xyz/ace/ATag; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/xyz/ace/ABehavior; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/xyz/ace/AContext; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/xyz/ace/AControl$List; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/xyz/ace/AControl; Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/xyz/ace/AData; UNEXPECTED TOP-LEVEL EXCEPTION: Error:Execution failed for task ':app:preDexDebug'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 2 

** Alternative Attempts: **

I really checked the entire project and recreated the project several times to make sure that I did not turn on this JAR several times, however I still get the same error "Error displaying the wrong image: java. Lang.IllegalArgumentException: already added ..."

I also reinstalled the Android SDK and also updated my JDK to jdk1.7.0_80, however I still get this error.

I am looking at other entries in stackoverflow that mention that I have to remove the link for library support version 4 or 7, which I also tried.

Other attempts:

I also check the actual JAR to see if several classes with the same name were created in the same package and which ones were not.

I also tried to add an obfuscation version that would have different class names, but there was an error in the confusing version of the JAR "Conversion error: java.lang.IllegalArgumentException error: already added: .."!

Question:

How can I solve this error "Do not intercept translation: java.lang.IllegalArgumentException: already added:" why the application: preDexDebug considers that there are several versions of my classes or is trying to add several versions ???

Thanks to a million everyone!

+7
java android android-studio illegalstateexception
source share
2 answers

You may have added the library two times:

  • addiction
  • in the library folder

Do not do this. Instead, keep one of these two ways. The jar file removal tool from the library folder will work best for you.

0
source share

I had the same problem, but the answer was related to the support library.

  compile 'com.android.support:appcompat-v7:21.0.0' 

Try creating a new application without library support or just try uninstalling it and see what happens.

UPDATE (you should also check if this is):

 android { compileSdkVersion 17 buildToolsVersion "17.0.0" sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } } } 
+2
source share

All Articles