Today I am faced with a massive error that doesn't let me run a sample project on my phone.
When Android Studio is building the project, it first shows the following targets as UP-TO-DATE:
....
:demoproject:processDebugResources UP-TO-DATE
:demoproject:generateDebugSources UP-TO-DATE
:demoproject:compileDebugJava UP-TO-DATE
:demoproject:proguardDebug UP-TO-DATE
....
There are dozens of these UP-TO-DATE log statements during the build process. However, they always halt at :demoproject:dexDebug. For dexDebug, I never seem to get an UP-TO-DATE log statement.
Instead, dexDebug is followed by this error:
:demoproject:dexDebug
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.xyz.corp.sample.project.demo.a) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
Now there are dozens of these Ignoring InnerClasses attribute errors. They even occur for classes in the v4 support library, which is truly perplexing.
Finally, these errors end with a new statement:
UNEXPECTED TOP-LEVEL EXCEPTION:
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.Main.main(Main.java:106)
...while parsing com/xyz/corp/sdk/AbcSDKConfig.class
1 error; aborting
Error:Execution failed for task ':demoproject:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 1
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
...while parsing com/xyz/corp/sdk/AbcSDKConfig.class
1 error; aborting
at com.android.dx.command.dexer.Main.processClass(Main.java:704)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
I have already consulted the following links:
1. Gradle finished with non-zero exit value 1.
2. What is the “Ignoring InnerClasses attribute” warning output during compilation?.
I'm not sure they apply to my situation. I'm not even able to run the project. I've updated my IDE to SDK Tools 22.0.1 and modified the buildToolsVersion tag in my build.gradle file, but to no avail. Can someone please guide me how to deal with this error ? All help will be appreciated.
Oh, and here is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
defaultConfig {
applicationId "com.xyz.corp.demo.project"
minSdkVersion 10
targetSdkVersion 22
versionCode 2060200
versionName '2.6.02.00'
}
buildTypes {
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def file = output.outputFile
output.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionName + ".apk"))
}
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.0'
compile project(':xyzSDK')
}
Please HELP !!!
Because it is reporting: bad class file magic (cafebabe) or version (0034.0000) you should check if you are compiling with the same java version that you are trying to use at runtime.
If you are using gradle you should use the following or similar entries in your build.gradle file:
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
Use this link for more gradle details.
In Android Studio, from File -> Project Structure -> SDK Location -> JDK Location you should use the jdk 1.7 and not relay on the Project level setting. See this link for a similar Android Studio question.
UNEXPECTED TOP-LEVEL EXCEPTION means that you are getting included twice any .jar.
As #Akhil said you should exclude support-v4 because I guess it's the main problem, but if #Akhil answer didn't help you try it out this method.
compile (':xyzSDK') {
exclude group: 'com.android.support', module: 'support-v4'
}
Have you tried to delete this line?
compile 'com.android.support:appcompat-v7:22.1.0'
Maybe :xyzSDK allready has appcompat-v7:22+..
I give you there a good answer by #CommonsWare to make a gradle report to see what's the problem.
I'm working for your answer, so if I find something interessant I'll be updating my answer.
Once you've done this you must Build -> Rebuild project
Also as I saw on #dan answer... I let you there a possible answer.
Instead of 1.7 as dan said try to :
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
Otherwise you can check it manually going to File > Project Structure or Ctrl+Alt+Shift+S and then on the JDK location see what are you using and if you are using 1.8 change to your 1.7 SDK path
And btw I think that I've read that you have asked if you could use JAVA 8 for Android instead of JAVA 7 if i'm not wrong.... and yes you could use JDK 8, but only if you also use gradle-retrolamba like says on this question..
It seems your libs folder & library project xyzSDK contains same library, which is causing issues while converting to dex
You can try to identify such library and remove it from one place.
Or excluding it like this
compile project(':xyzSDK'){
exclude module: 'support-v4'
}
I have taken example of support-v4, as i have faced similar issues due to this one previously.
Related
My AngularJS based Cordova project facing various Android build issues recently. It was in gradle version of 2.14.1 with build tools of 2.2.3. However, faced issue as "A problem occurred configuring root project ".
I tried removing android platform and adding again with platform version 6.4.0,
Recent error While perform Cordova build android:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':transformClassesWithMultidexlistForDebug'.
java.io.IOException: Can't write [/Users////platforms/android/build/intermediates/multi-dex/debug/componentClasses.jar] (Can't read [/Users/****/.gradle/caches/transforms-1/files-1.1/support-v4-23.4.0.aar/21482513ed63a92f167953e0b46db339/jars/classes.jar(;;;;;;.class)] (Duplicate zip entry [classes.jar:android/support/v4/util/ArrayMap.class]))
I tried using multiDexEnabled as true in defaultconfig, but error remains same,
Project.properties :
target=android-26
android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-android-support-gradle-release/stcmobile-cordova-android-support-gradle-release.gradle
cordova.system.library.1=com.android.support:support-v4:24.1.1+
cordova.system.library.2=com.android.support:support-v4:+
cordova.system.library.4=com.android.support:multidex:1.0.1
Build.gradle :
android {
......
defaultConfig {
multiDexEnabled true
}
compileSdkVersion 26
buildToolsVersion '26.0.2'
.......
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
......
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
implementation(project(path: "CordovaLib"))
compile "com.android.support:support-v4:24.1.1+"
compile "com.android.support:support-v4:+"
compile "com.android.support:multidex:1.0.1"
// SUB-PROJECT DEPENDENCIES END
}
}
I'm not in a position to migrate the application to latest Angular and hence this build related issues needs to be fixed.
current Versions details,
Cordova Android : 6.4
Cordova : 7.1
Gradle : 4.1
com.android.tools.build:gradle : 3.0.0
compileSdkVersion 26
buildToolsVersion '26.0.2'
After multiple trial and check with various compile sdk and build tools versions, the errors got eliminated and still running the project.
The library I'm using is bychan, I can't even include it in a Nougat empty app project either loaded as module or through jar.
So this is an example of what was returned in Android Studio's messages:
Can someone explain what they mean by "unknown interface" in the errors below?
Error:TokenDefinitionBuilder.java:118-119: Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.function.Function
Error:TokenDefinitionBuilder.java:118-119: Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.function.Predicate
...
Error:com.android.jack.JackAbortException
This came from a library I've used. I thought adding the types in angle brackets would help? I don't know if it did anything though.
This is the line 118-119 in that library:
strings.stream().<StringMatcher>map(StringMatcher::new).map(
m -> m.tryMatch(input, searchStart)).filter(Objects::nonNull).findFirst().orElse(null));
I'm not sure what it is complaining about? What should I do or change to evade this problem? I had thought that maybe Android doesn't support Lambda Expressions, but the error clearly stated "Lambda coming from...", which means it recognized I used a lambda expression.
Please help.
Update
I have included the library by compiling it in a jar inside another jar library, if that helps. I'm new to the world of Android if you can't tell.
Updates 2
I don't think this is related to the API version? I've set my build target to 25. But the build is still failing.
Also, if you look below, I don't see an option for 1.8? But I've set the build JDK to my 1.8 JDK location.
Gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "this.is.where.i.have.my.id"
minSdkVersion 25
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
jackOptions {
enabled true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
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:25.0.1'
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:preference-v7:25.0.0'
compile 'com.android.support:preference-v14:25.0.0'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.8.0'
compile files('libs/my_lib_that_contains_lambda.jar')
}
I would not suggest to use java 8. It is not supported nowadays. But, even, it will: remember, that each devices has got its own java machine that will not update. I mean, if you wanna be sure your app works properly setup your project as java 6. Old devices this never support up-to-date JMV
Read this discussion too
Which JDK version (Language Level) is required for Android Studio?
Android SDK < 24 does not support java.util.function.Function and java.util.function.Predicate interfaces because Java 8 allows functional interfaces to contain default methods which is only supported in SDK 24 and above. I had this problem when I was using consumers, and the way I fixed it was to create my own clown of java.util.function.Consumer interface without all the default methods.
You can also fix this issue by increasing the minimum SDK of your app to 24.
Update
Add the following to your build.gradle file
defaultConfig {
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Overall set up looks good to me except for the Java JDK 1.8 part.You need to set a correct path to JDK installation folder in Android Studio in order to use all the new Java 8 features.
I know these kind of questions were asked here tons of times and none of the provided solutions helped.
I recently tried to add BoofCV to my Android Studio Project using Gradle:
apply plugin: 'com.android.application'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.as.recognize2"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
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.1.1'
compile group: "org.boofcv", name: "all", version: "0.26"
compile group: "org.boofcv", name: "android", version: "0.26"
testCompile 'junit:junit:4.12'
}
This is what my build.gradle (app) looks like.
The Gradle Sync succeed but the "Run App" - Build failed giving me errors like these I picked from another question because I have changed much in my project and changing it back would be very difficult.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.apache.log4j.chainsaw.ControlPanel$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
I get tons of these Errors
And i don't wont to ignore the inner class attributes in proguard configs.
Because of these errors the build takes hours.
Then I downloaded all the Jar - Files from The Boof-CV-Site and embedded them into the libs folder and out-commented the compile commands which use maven to download boofcv. Result:
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
As you can see at the top of the page I already implemented it. But I can't use the java plugin since I am using the Android.Application Plugin already. And switching back to Java 7 won't work because the new Android Studio 2.2.3 does not support it.
Now I downloaded the source code and embedded them by using File->New->New Module->Import Gradle and navigating to the sources build.gradle. But it contains so many build gradles which all don't know the idea command
and which all don't contain the apply plugin: "java" command and therefore are not able to use the compile function. So I would have to edit each build.gradle (many build.gradle's) by hand.
How can I clearly install Boofcv in Android Studio 2.2.3 or above?
I'm not sure what's wrong but here's a working example that I verified last week: source code This is from the latest SNAPSHOT code, but it's configured to use the previous stable release.
EDIT: Check out the first subsection on this wiki page
I am currently working on an Android app and I am attempting to retrieve information from a MySQL database. I am trying to use JDBC as instructed by my professors, but I keep running into problems.
I have installed the MySQL Connector/ODBC 5.3, set a CLASSPATH environment variable for the driver I am attempting to use, which is "mysql-connector-java-5.1.38-bin.jar", and I attempted to import that JAR into my project.
I have attempted to import the JAR in two ways, which are the following:
File > New Module > Import .JAR/.AAR Package > import the mysql connector JAR
Then I proceeded to go to File > Project Structure > app > Dependencies > add module dependency
The other way I have attempted to do this was by adding the JAR into the "libs" folder of my project and follow the Project structure path to add a dependency from file.
I am running the latest version of Android Studio 2.0
The build completes successfully when following either of the importing steps however when doing so I get the following error when attempting to run the app:
Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
> JSR/RET are not supported with computeFrames option
The only solution I found relevant to this was going to Android Studio Settings and turning the Instant Run option off.
After doing so I received the following error instead:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_77\bin\java.exe'' finished with non-zero exit value 1
The following is my build.gradle(Module:app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
applicationId "com.example.JohnDoe.myapp" //This is not actually the name or the name of the app on there but I changed this for privacy.
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
javaMaxHeapSize "2048M"
jumboMode = true
}
}
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.2.1'
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.android.support:multidex:1.0.1'
compile project(':mysql-connector-java-5.1.38-bin')
}
The following is a link to the whole gradle console output after turning "Instant Run" off: pastebin.com/5kj6Cgeb
Please advise me where to go from here to get the JDBC driver working so I can finish this project. Thank you for your time.
UPDATE 1: Apparently the latest JDBC driver is not fully compatible with Android and causes issues. I installed and imported the previous version (5.0.8) and so far the app at least runs. Will be attempting to implement the driver now and actually develop with it, at which time I will post another update on the outcome.
You should not use JDBC in Android Apps as it is targetted to high bandwith, reliable connections to a database server, something you will not achieve on a mobile device. Try to wrap your database in a REST web service instead.
I've read several times that people struggled with using JDBC in Android, it's just not built for beeing used in the Android ecosystem. Not every library is fully compatible with Android, your gradle output suggests that the "dexer" could not convert the jar file to a .dex.
Your provided gradle output show the following error:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
See this question for a possible solution. Ensure you are building with the right Java SDK.
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_79\bin\java.exe'' finished with non-zero exit value 1
Here is my gradle build file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "br.com.gerenciarsc.nfce"
minSdkVersion 12
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile('org.simpleframework:simple-xml:2.7.1') {
exclude group: 'xpp3', module: 'xpp3'
exclude group: 'stax', module: 'stax-api'
exclude group: 'stax', module: 'stax'
}
compile 'com.google.code.gson:gson:2.5'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.beardedhen:androidbootstrap:2.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:design:23.1.1'
compile 'com.journeyapps:zxing-android-embedded:3.0.2#aar'
compile 'com.google.zxing:core:3.2.0'
compile 'br.com.uol.ps:library:0.8'
compile 'com.android.support:support-v4:23.1.1'
compile 'javax.xml.crypto:jsr105-api:1.0.1'
compile ('commons-io:commons-io:2.4'){
exclude group: 'org.apache.commons.collections', module: 'org.apache.commons.collections'
}
}
I faced the same issue. Scrolling down, I found the following error in the logs:
java.lang.UnsupportedClassVersionError: com/android/dx/command/Main :
Unsupported major.minor version 52.0
Then I searched for the above error and found the following work-around as suggested by the solutions to this question and another similar question:
In the file build.gradle(Module:app) I changed the following from:
buildToolsVersion "24.0.0"
to
buildToolsVersion "23.0.2"
and clicked the button to "sync project with gradle files" in Android Studio and the error vanished.
Note: I didn't understand the exact reason for the error and it's solution completely but it seems to be a compatibility issue of java version 1.7 and Android API level 24. Some people suggested (on the questions' links I mentioned) to use JDK version 8 with API 24, or downgrade it to JDK version 7 and API level 23.0.x as a work around.
Found cause and solution.
All at the sudden this happened, when I created a class with the same signature (package and name) in 2 different projects of my environment and started the App to try it. Got that message.
I discovered it by adding multiDexEnabled true and new error message appeared with duplicated class found.
So, I refactored the class (changed package name), also removed multiDexEnabled support as it was before, the App started.
I also faced the same issue after did reach i got resolved. issue could be the classes folder not created under build directory while you build the project, the reason for that the project path may not correct. so you have to correct the project path and rebuild that it will work fine. java files should be under path \src\main\java for gradle proejct
I've got this error:
Execution failed for task
':vvm:transformClassesWithDesugarForRelease'.
com.android.build.api.transform.TransformException:
org.gradle.process.internal.ExecException: A problem occurred starting
process 'command 'E:\Java\jdk1.8.0_181\bin\java.exe''
I've solved it by updating gradle from 4.4 to 5.4
I also faced the same issue after did reach i not resolved. instead of applied two approaches as follows:
Process 1: Update plugin with build.gradle
plugins {
id "com.github.ManifestClasspath" version "0.1.0-RELEASE"
}
Process 2: Update the JAVA path while executing the application inside the IDE
Still it is not working.
In my case, I changed buildToolVersion in build.gradle(module:app) to 23.0.2
then the app is running.