I'm running into an exception in a gmail client I'm working on. The exception is the
java.lang.NoClassDefFound that is triggered on the getDefaultInstance line
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
I've included the javax jar as follows:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.3.0'
compile 'com.google.api-client:google-api-client:1.20.0'
compile 'com.google.api-client:google-api-client-android:1.20.0'
compile 'com.google.api-client:google-api-client-gson:1.20.0'
compile 'com.google.apis:google-api-services-gmail:v1-rev29-1.20.0'
compile 'javax.mail:javax.mail-api:1.5.2'
}
I've googled this but not quite sure how to fix this. I've tried clean and rebuild and in both cases the exception is still thrown. Any help would be appreciated.
Exeception detail Message:
Didn't find class "com.sun.mail.util.MailLogger" on path: DexPathList[[zip file "/data/app/com.android.application.androidgmailclient-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
UPDATE
I found that the missing class "MailLogger" is not a part of the javax.mail-api rather it is a part of the 'javax.mail:mail:1.5.0-b01' jar with 1.5.0-b01 being the latest version:
http://mvnrepository.com/artifact/javax.mail/mail/1.5.0-b01
So I included the compile 'javax.mail:mail:1.5.0-b01' into my gradle file and then I found the jar in the external libraries. I copied the jar into app/libs and then hit "Add as Library". I can see that the MailLogger class is now present which is what was bombing in the exception. My gradle file now looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
packagingOptions{
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
defaultConfig {
applicationId "com.android.app.androidgmailclient"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.3.0'
compile 'com.google.api-client:google-api-client:1.20.0'
compile 'com.google.api-client:google-api-client-android:1.20.0'
compile 'com.google.api-client:google-api-client-gson:1.20.0'
compile 'com.google.apis:google-api-services-gmail:v1-rev29-1.20.0'
compile 'javax.mail:mail:1.5.0-b01'
compile files('libs/mail-1.5.0-b01.jar')
}
However, when I go to build the project now I get this build error:
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
Any ideas?
Not sure if you solved this already, but I found you need to use an Android specific Java Mail library.
compile 'com.sun.mail:android-mail:1.5.5'
compile 'com.sun.mail:android-activation:1.5.5'
I was running into your error and other similar ones using the latest Java Mail libraries but switching to these fixed all of them.
https://java.net/projects/javamail/pages/Android
Android Studio: NoClassDefFoundError
This error occurred because you are adding same library twice.
compile 'javax.mail:mail:1.5.0-b01'
compile files('libs/mail-1.5.0-b01.jar')
delete one of these line then I think it should work fine.
I assume you have compiled your code successfully, but got a runtime exception. You need to include the jar files in the final package. Have a look at this one, and this one.
Related
UPD. I have read these question and answer (Class file for com.google.android.gms.internal.zzaja not found). But I doesnt understand what strings i need to add or remove in my project.
Because I havent this and other strings in my code:
compile 'com.google.android.gms:play-services-location:9.2.0'
I develop an android app with use of FireBase. And when I want to build my project I have an error:
Error:(39, 25) error: cannot access zzanb
class file for com.google.android.gms.internal.zzanb not found
The error was caused by invoking statement: FirebaseAuth.getInstance().getCurrentUser();
Projects build.gradle:
// 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.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Modules build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "xxx.yyy.zzz"
minSdkVersion 19
targetSdkVersion 25
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(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.google.firebase:firebase-core:10.0.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.1.0'
compile 'com.firebaseui:firebase-ui:0.6.0'
compile 'com.android.support.test.espresso:espresso-core:2.2.2'
}
apply plugin: 'com.google.gms.google-services'
Please, help me to solve that error)
P.S I have already read that question (Firebase Error cannot access zzanb after using play-services-xxx:9.8.00), but i didnt understand anything, what i need to add or remove from my build.gradle files in my situation.
You're mixing libraries from old and new Firebase released. Everything from Firebase that you use should be in parity. This line is reference an library from a very old Firebase release (before it became the Firebase platform at Google):
compile 'com.firebaseui:firebase-ui:0.6.0'
If you want to use the Firebase-UI library, you should use the new version of it that matches the version of the main client library you're using. You're using 10.0.1, so according to the table on the Firebase-UI github I just linked, you want this dependency:
compile 'com.firebaseui:firebase-ui:1.1.1'
Always make sure your Firebase-UI library matches the core Firebase SDK you're using.
It looks like in your case Doug's fix resolved your issue, but we recently encountered the same problem with a different root cause.
In our case, we had configured our IDE project to use JDK8 but failed to check which version of the JDK was in use in the terminal. Because React Native runs Gradle from the command line when you type 'react-native run-android' Gradle was attempting to build using JDK10 which caused obvious issues since Android currently only supports up to JDK8. Once we configured the terminal to use JDK8 the issue was resolved.
TL;DR: Check what version of the JDK you are using in the terminal.
Getting following error:
error: cannot access zza
class file for com.google.android.gms.common.internal.safeparcel.zza not found
dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-analytics:17.0.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.android.support:support-v4:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
/* implementation 'com.google.firebase:firebase-core:9.2.0' // this line must be included to integrate with Firebase
implementation 'com.google.firebase:firebase-messaging:10.2.1' // this line must be included to use FCM*/
//implementation 'com.google.android.gms:play-services:10.2.1'
implementation 'com.google.android.gms:play-services-maps:10.2.1'
implementation 'com.google.firebase:firebase-core:10.2.1'
implementation 'com.google.firebase:firebase-messaging:10.2.1'
}
I am using external third party libraries in my project, but the problem I am facing is, two different jar files contains a class with the same name.
Following are the libs I am using
jaxen-1.1-beta-2.jar
jaxen-core.jar
The above given jar files share a class with the same name called "DefaultNavigator.class" so because of this i am getting the following duplicate class error.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/jaxen/DefaultNavigator.class
I need to know whether i can edit/delete unused classes or repeated classes given in the external third party jar files or please guide me whether i can copy only the classes that i required from all the jars and put them up in a single jar file and use. if this is possible please tell me how to do this. I am a beginner to android. Below I am attaching my build.gradle file.
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xxx.xxx.yyy"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:multidex:1.0.1'
compile files('libs/xsdlib-1.5.jar')
compile files('libs/relaxngDatatype-2.2.jar')
compile files('libs/javax.xml.stream.jar')
compile files('libs/pull-parser-2.jar')
compile files('libs/javax.xml.bind.jar')
compile files('libs/java-rt-jar-stubs-1.5.0.jar')
compile files('libs/jaxen-core.jar')
compile files('libs/jaxen-dom4j.jar')
compile files('libs/jaxen-1.1-beta-2.jar')
}
So i recently switched my Android Studio default JDK to Java 8, so I could use Lambda expressions. I had to enable Jack to let the gradle build, but now when I try to rebuild my applicaiton, I am getting about 3 different errors that seem to be coming from Jack. I can't seem to find the root of any of these problems, and would like to stay building with J8. Any insight or help for this is much appreciated. Here are the errors I am getting during build:
1)
Error:Library reading phase: Type javax.inject.Named from file
'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar'
has already been imported from file
'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar',
type 'javax.inject.Named' (see property 'jack.import.type.policy' for
type collision policy)
2)
Error:com.android.jack.JackAbortException: Library reading phase: Type
javax.inject.Named from file
'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar'
has already been imported from file
'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar',
type 'javax.inject.Named' (see property 'jack.import.type.policy' for
type collision policy)
3)
Error:com.android.jack.backend.jayce.TypeImportConflictException: Type
javax.inject.Named from file
'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar'
has already been imported from file
'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar',
type 'javax.inject.Named' (see property 'jack.import.type.policy' for
type collision policy)
4)
:app:compileDebugJavaWithJack FAILED
Error:Execution failed for task ':app:compileDebugJavaWithJack'.
java.io.IOException: com.android.jack.api.v01.CompilationException: Library reading phase: Type javax.inject.Named from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-2.4.0-b10-e2682135301b663484690f1d3a4a523bcea2a732.jar' has already been imported from file 'C:\Users\nicholas\AndroidStudioProjects\BaseIntegrations\app\build\intermediates\jill\debug\packaged\javax.inject-1-4a242883e90a864db3b80da68e11a844f842d2df.jar', type 'javax.inject.Named' (see property 'jack.import.type.policy' for type collision policy)
Here is the app level build.gradle:
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.nicholas.baseintegrations"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
jackOptions {
enabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
useLibrary 'org.apache.http.legacy'
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:24.2.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile project(path: ':backend', configuration: 'android-endpoints')
compile "com.getbase:basecrm-java:1.4.3"
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:palette-v7:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'
compile group: 'org.glassfish.jersey.media', name: 'project', version: '2.23.2', ext: 'pom'
}
All help is very appreciated, as I know this is a new things, but cannot seem to find questions regarding the Jack/J8 build process. Thanks in advance.
We're looking into this, I think it's due to different behavior of the Android Gradle plugin for Jack and javac. As a workaround, you can try this in jackOptions
additionalParameters = [ "jack.import.type.policy" : "keep-first" ]
But be aware that with that option, Jack will keep the first definition of the class it encounters.
You can track our progress here: https://code.google.com/p/android/issues/detail?id=222273
I ended up solving this build issue. One of my dependencies was adding a second javax.inject library which was throwing these build errors saying that the javax.inject jar had already been imported from a previous one.
So I had javax.inject-1 and javax.inject-2.4.0-b10. I ended up excluding the javax.inject module from one of my dependencies and it cleared up issues with the build and is working jsut fine now.
Here is the dependencies section of my app build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(path: ':backend', configuration: 'android-endpoints')
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'
compile (group: 'org.glassfish.jersey.media', name: 'project', version: '2.23.2', ext: 'pom')
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services-gcm:9.4.0'
compile ('com.getbase:basecrm-java:1.4.3') {
exclude (group: 'javax.inject', module: 'javax.inject')
}
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:palette-v7:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
}
And you can see the group exclusion in the basecrm dependency. So if anyone else has this issue just watch out for duplicate External Libraries coming from some dependency import.
I met the same problem,Then I found a same package in these two jar,But them are not a same version.
So modify to them have a same version.
I have an issue with gradle when importing this mongoDB jar driver in android studio. I am getting this error:
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 2
When i import the mongo-java-driver-2.13.0-rc0.jar driver i have no issue with this. I do not know if this is relevant but first i imported this driver and then any other mongoDB driver is having this error except from this one that i added first. Here is my gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
repositories {
mavenCentral()
jcenter()
}
defaultConfig {
applicationId "com.example.irakl_000.maps"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:percent:23.1.0'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.isseiaoki:simplecropview:1.0.13'
compile files('libs/mongo-java-driver-3.2.0-SNAPSHOT.jar')
Any answers to similar questions in stackoverflow did not help, so any help is much appreciated!
EDIT: I created a new project and there are no errors, so obviously something is wrong with the project and not with the grandle file or jar
EDIT:
When i run gradle compileDebug --stacktrace i get the following
* Exception is:
org.gradle.execution.TaskSelectionException: Task 'compileDebug' is ambiguous in root project 'Maps'. Candidates are: 'compileDebugAidl', 'compileDebugAndroidTestAidl', 'compileDebu
gAndroidTestJavaWithJavac', 'compileDebugAndroidTestNdk', 'compileDebugAndroidTestRenderscript', 'compileDebugAndroidTestSources', 'compileDebugJavaWithJavac', 'compileDebugNdk', 'c
ompileDebugRenderscript', 'compileDebugSources', 'compileDebugUnitTestJavaWithJavac', 'compileDebugUnitTestSources'.
at ...
You may have a problem with the limit of 65k methods allowd on an android studio project. Google announced a solution to this problem. You can find more information here. I had a similar problem and this was the solution for me so you could give a try.
UPDATE
I should mention that this could seriously reduce your gradle build time so you should use it only if there is no other way. The best think you can do is to reduce the libraries you use to the ones you need.
You can also refer to this answer to reduce your google-play-services to the ones you actually need.
It looks like you're depending on a single jar twice between these two dependencies:
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/mongo-java-driver-3.2.0-SNAPSHOT.jar')
The first line is declaring a dependency on everything in the libs directory. The second line is then adding another dependency on a specific jar in the libs folder, which was already covered in the first line. You're effectively telling gradle to use that jar twice, which could cause problems. You're probably also getting a message from gradle to run the build again with different command line flags to see more detailed errors, so do that as well.
Consider removing one or the other. If you have other jars in the libs folder, you'll probably want to remove the second line.
I get this error when I try to run the app
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_25\bin\java.exe'' finished with non-zero exit value 2
Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.dusanp.passer"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
compile fileTree(include: 'Parse-*.jar', dir: 'libs')
compile 'com.android.support:support-v4:23.+'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/sinch-android-rtc-3.7.1.jar')
}
Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration
This might be due to exceeding the 65K methods dex limit imposed by Android. This problem can be solved either by cleaning the project, and removing some unused libraries and methods from dependencies in build.gradle, or by adding multidex support.
Setting up your app development project to use a multidex configuration requires that you make a few modifications to your app development project. In particular you need to perform the following steps:
Change your Gradle build configuration to enable multidex
Modify your manifest to reference the MultiDexApplication class
Here is the complete details: https://developer.android.com/tools/building/multidex.html