I'm setting up a project to work with Androids NDK. By that I have to use the experimental Gradle plugin. Gradle syncs without errors and the make is without errors.
But when I try to 'run app' Gradle gives this error message:
UNEXPECTED TOP-LEVEL EXCEPTION:
Error:com.android.dx.cf.iface.ParseException: bad class file magic
(cafebabe) or version (0034.0000) at
com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at
com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at
com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at
com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.parseClass(Main.java:764) at
com.android.dx.command.dexer.Main.access$1500(Main.java:85) at
com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)
at com.android.dx.command.dexer.Main.processClass(Main.java:749) ...
19 more
From previous questions I can see that it might depend on me using Java 8 and Android requiring Java 7. But my other projects compile and run without this issue.
I missed this answer and the code snippet that solved the problem.
model {
android {
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
... //rest of gradle code
}
}
Sloppy research from my side.
Related
I'm using Kotlin version 1.3.7 . So when I upgrade to 1.4.10 I get the compiler error
Cause: cannot find META-INF.versions.9.module-info: module-info found in META-INF/versions/9/module-info.class
Is there any help?
Please add the following code inside android block which is present in your app-level gradle file.
android
{
...
packagingOptions {
exclude 'META-INF/atomicfu.kotlin_module'
}
}
I would like use some features from Java 9 and 10 in my PC java application which has common code with android app.
When I use jdk 10 or jdk 9 android application is building, but it doesn't launch(it is throwing a lots of errors). When I use jdk 8 for whole project everything is working correctly without any error. When I manually build project using 2 different jdk everything is working fine.
I tried set targetCompability and sourceCompability for android application for JavaVersion.Version_1_7 but it doesn't help. I tried use different jdks for java 9 and java 10 but it doesn't help with this problem.
I would like build android application and common component with jdk8 and other components with jdk10. Is it possible to force gradle to use different jdk for specific project without using external tools like bash?
My project structure looks like:
build.gradle
common-component(jdk8)/build.gradle
PC(jdk 10)/build.gradle
device-Android(jdk 8)/build.gradle
I found workaround. It works fine with gradle 4.7(Java 10 support was added in this release). This hack/workaround requires to launch project using lower JDK like Oracle JDK 8 or OpenJDK. We can build some components using higher version of JDK, but we can't build JDK project with JDK10 and then use it with JDK8 if we specify targetcompablility higher than 1.8. It will work only for java project and probably it won't work for android plugin and other JVM languages.
Part of build.gradle for PC application :
project (':pc-client') {
dependencies {
compile project(':net-default')
testcompile JUNIT
}
compileJava {
options.fork = true
options.forkOptions.javaHome = file('/usr/lib/jvm/java-10-oracle')
targetCompatibility = 1.10
sourceCompatibility = 1.10
}
compileTestJava {
options.fork = true
options.forkOptions.javaHome = file('/usr/lib/jvm/java-10-oracle')
targetCompatibility = 1.10
sourceCompatibility = 1.10
}
}
I am using log4j in one of my Android lib projects. Now I updated the log4j version from 2.3.0 to 2.9.0 and building the lib project is successful and also I was able to successfully add this lib project to my main project as a dependency. But when I run my project, I get the following error.
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 53 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.
...while parsing META-INF/versions/9/org/apache/logging/log4j/util/ProcessIdUtil.class
To over come the above error I made the following changes in the gradle.
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
...
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
After the above changes I got the following error while running the project.
Error:Jar transformation: class files coming from an unsupported Java
version Error:Execution failed for task
':MyApp:transformClassesWithPreJackPackagedLibrariesForDebug'.
com.android.build.api.transform.TransformException: com.android.builder.core.JackToolchain$ToolchainException: Jack compilation exception
Now I am not getting a proper solution for this problem. Even I raised this in log4j forum (https://issues.apache.org/jira/browse/LOG4J2-2038). But the provided solution doesn't explain much.
Mean while I am trying to work directly with the log4j android code from here .
This has become a blocker for me. Any help will be appreciated. Thanks.
I am new to using Realm database for Android.
I modified my gradle files to include the Jack toolchain so that I could use Java 8 language features. I also modified the gradle files to install the Realm plugin. When I synced the project gradle files, I received the following error: Error:Could not find property 'options' on task ':app:compileDebugJavaWithJack'. The two modifications work fine on their own, but for some reason I cannot have both at the same time.
I would very much appreciate help on this matter.
It is not possible to use Jack compiler with Realm at the moment, because Jack does not support bytecode manipulation (Javassist / Transform API).
In order to use lambdas, it's easier for you to use Retrolambda instead for the time being.
buildscript {
//...
dependencies {
classpath "io.realm:realm-gradle-plugin:1.1.0"
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}
}
And
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Unfortunately Jack compiler and Realm can't play together right now. Please follow that topic. That one is also useful.
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.