Unable to fix "ParseException: bad class file magic (cafebabe) or version (0034.0000)" - android-studio

I recently imported a jar from my AWS application that contains all the objects I am going to be referencing on my Android application. As soon as that is in my Android Studio project and hooked up via Gradle, the error shows up and doesn't go away until I clear out my imported jar and rebuild everything.
What I read:
This error can be legitimate. This can happen when an Android application surpasses 65k method names. My application may be big, but I would be amazed if all the libraries I imported totaled over that.... I won't rule it out, but that is a lot of methods. From what I saw, nine times out of ten, this was a configuration bug. The first couple articles I read said to enable Proguard to remove all unused methods, but that didn't help.
My configuration:
I have everything on my Android Studio environment set to run Java 7:
Project bytecode version: 1.7
JDK location: C:\Program Files\Java\jdk1.7.0_45
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.maveric.helloworld"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:4.2.42'
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'com.cedarsoftware:json-io:4.3.0'
}
I have spent the last 5 hours trying every single solution on SO, and haven't had a single bit of luck with any of them.

After over 6 hours of trying solutions, the one Oleg linked me in the comments finally led me to the real cause of the problem.
The brief explanation of the issue can be found HERE, but I will try to explain how everything looked on my system:
This error first showed up for me when I imported a jar file that was part of my main Java project, which was hosted in Eclipse.
The way this error first pokes up to the user is through the Messages tab where Gradle walks through each of its tasks. The task that it crashes on is
:app:transformClassesWithDexForDebug
The problem is the Gradle Messages window just says the task failed and then gives a non-descriptive error message saying
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_45\bin\java.exe'' finished with non-zero exit value 1
In order to get a better view, you need to go look at the Gradle Console view. The text in the terminal view tells you this:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_45\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Scrolling up a little bit shows that the stacktrace came through just fine, even though this initial message hints that there should be additional flags added for debugging. The top of the stacktrace says this:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
But even that doesn't help very much. What it is trying to tell you (very poorly I have to add) is that the class it is looking at was compiled with a Java version that is not supported. In my case, version (0034) was the hex representation of 52 which means Java 8. Android doesn't support Java 8, so it terminates the build.
The solution was to go back to my Eclipse project and export the jar file with the compiler set to version 1.7 and now everything is up and running again. I hope this helps!

Related

Android Studio 3.0.1 (Windows 10 64-bit) stuck at "Executing tasks: [:app:assembleDebug]" when building project

The process gets stuck if I am trying to run the app (even when I start from a fresh new project) both on an emulator (Android 5.0 or 6.0) or on my phone (Android 7.1). Following some results I found online, I tried to run gradle offline but it did not work. I did also try the solutions suggested on this link, with no success. On Ubuntu, this seems to be caused because of a library issue concerning 32-bit software running from a 64-bit system, which can be solved installing the appropriate library, but I could not find any guidance when running Android Studio on Windows.
The build.gradle file (Module: app) says:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.denny.zuzuplayer"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
The build.gradle (Project) says:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Thanks!
I noticed that Android Studio has a tab called Gradle Console, which lists every gradle process that is currently running, in detail. That is how I got the message that the "aapt" instance was not fine the old rascal, due probably to the antivirus software. This is what the console told me:
> Exception in thread "queued-resource-processor_16"
> java.lang.RuntimeException: Timed out while waiting for slave aapt
> process, make sure the aapt execute at
> C:\Users\Denny\AppData\Local\Android\Sdk\build-tools\26.0.2\aapt2.exe
> can run successfully (some anti-virus may block it) or try setting
> environment variable SLAVE_AAPT_TIMEOUT to a value bigger than 5
> seconds
I have no idea how to "set environment variable SLAVE_AAPT_TIMEOUT to a value bigger than 5 seconds". I Googled the issue for a few minutes when I wondered, why not try the other possible solution first?
I added the SDK folder to my antivirus exceptions (aapt is an instance of SDK, for that matter), and voilĂ , the project is finally building. Hurray!
I just got this error and was able to resolve it by ensuring that the two Glide libraries I'm using refer to the same version.
This caused the error:
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
And this fixed it:
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
I was able to determine that the error was related to the Glide libraries, at least my configuration of them in the module's build.gradle file, by using Denny's suggestion to examine the Gradle tasks. Opening the Gradle Tool Window shows a list of tasks. The Event Log indicated that the error was related to the "assembleDebug" task. So, I double-clicked on that task in the Gradle Tool Window to execute it, and some useful information appeared in a tab on the Run console.

Unable to build NDK project from latest Android Studio (version 2.1.2, Windows 64 bit)

I am unable to build a NDK project from the Android Studio environment but can build it manually using the command console.
I get the following error after building:
Error:Execution failed for task ':xxxxxx:compileReleaseNdk'.> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\xxxxx\AppData\Local\Android\SDK\android-sdk\ndk-bundle\ndk-build.cmd'' finished with non-zero exit value 2
I got a similar error while invoking ndk-build.cmd manually using the console from the jni directory where my NDK project is stored.However I fixed it by modifying the following in my Application.mk file as follows:
NDK_TOOLCHAIN_VERSION := 4.9
since 4.9 is the tool chain available on my install. I suspect from the Android Studio environment, the toolchain version is being picked incorrectly, and yet I do not know where to set this option in the GUI.
The build.gradle file has the following NDK block:
ndk{
moduleName "xxxxxx"
ldLibs "log"
cFlags "-std=c++11 -fexceptions"
stl "gnustl_static"
abiFilters "arm64-v8a armeabi armeabi-v7a mips mips64 x86 x86_64"
}
Please advise me on how to go about solving this problem.
Just out of curiosity, I moved my project directory to the desktop and tried to build that project. The build was successful.
Finally narrowed down the problem to the NDK compiler not being able to create the following intermediate object file inside my project folder:
C:\Users\xxxxx\GitRepos\REVIEWS\xxx\SMART-xxx\xxxx-xxx-androidnative\xxxLibraries\xxxlibrary\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/natXXXX/C_\Users\xxxxx\GitRepos\REVIEWS\xxx\SMART-xxxx\xxxx-xxx-androidnative\xxxLibraries\xxxlibrary\src\main\jni\NativeXXXX.o.d
The reason was the well known windows path cannot exceed 255 characters issue. As you can see above the NDK-Build utility tries to append a deep folder hierarchy like "C_\Users\xxxxx\GitRepos\REVIEWS\xxx\SMART-xxxx\xxxx-xxx-androidnative\xxxLibraries\xxxlibrary\src\main\jni\" which exceeds MAX_PATH.

Cannot Resolve R after Update Android Studio to v13

I've got problem when executing gradle after my android studio updated to version 1.3
So this is the error message
Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Otniel\AppData\Local\Android\sdk\build-tools\22.0.1\aapt.exe'' finished with non-zero exit value 1
I don't know what was happened, but this is my approach to fix my error (which is not produce any working solution)
change my build tools from project structure settings :
compile sdk version : API 22: Android 5.1
build tools version 22.0.1
(sync gradle and error still the same with the above message)
Then I continue the first setting (point 1) and add this 2nd setting
2. change gradle 1.2.3 to classpath 'com.android.tools.build:gradle:1.3.0'
(1.2.3 produce the same error as the message above)
(with 1.3.0 still produce the same error)
try to revert back the build tools to v 21 and android lolipop v 5
with combination of gradle : com.android.tools.build:gradle:1.3.0, and com.android.tools.build:gradle:1.2.3
When I revert to 1.1.3 or 1.0.0 (for the gradle plugin) I still got the same error.
When I change the gradle to 1.1.3, the console returns a message to use the gradle plugin version that match with build tools sdk (v 24)
But every combination that I use is still return an error message (still the same, like the message above)
Also I've tried to delete impl and .idea folder, and reimport the project, still have the same error.
And my android studio cannot resolve R symbol as the effect.
So what should I do to fix this?
[EDITED]
This is my gradle code :
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.vanwellis.vinnomobile"
minSdkVersion 15
targetSdkVersion 21
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:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:support-v4:21'
compile 'com.daimajia.easing:library:1.0.0#aar'
compile 'com.daimajia.swipelayout:library:1.2.0#aar'
compile 'commons-io:commons-io:2.4'
compile 'com.daimajia.androidanimations:library:1.1.2#aar'
compile 'com.nineoldandroids:library:2.4.0'
compile 'jp.wasabeef:recyclerview-animators:1.0.3#aar'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.google.code.gson:gson:2.3.1'
}
I got these 2 errors, after seeing it carefully :
D:\Projects\Android\MyProj\app\build\intermediates\res\merged\debug\drawable-hdpi-v4\ic_launcher.png: error: Duplicate file.
D:\Projects\Android\MyProj\app\build\intermediates\res\merged\debug\drawable-hdpi\ic_launcher.png: Original is here. The version qualifier may be implied.
Maybe my additional information are usefull
After updating Android Studio recently, I also had this problem. What worked for me was to expand res, then go through every child folder in res and expand them (you can close them right after.)
Close all classes you have open and in the system bar select Build > Make Project.

How to port C library into into Android studio JNI folder

I have a program, which I have compiled using the arm toolchain in NDK. Now I want to use it as a library; put it in the JNI folder and call the functions from my main activity. I want to know how to go about this efficiently and intelligently. I copied all the files, and folders over to the JNI folder. What do I do about the make files in my native C code? Can I modify them to fit the JNI setup? Can anyone help with what items I need to address please? Note, my question is not about porting the native code, rather how to do it effectively. And I am trying to figure out if there are any automation tools in IDE that would help me do this please.
Right now, I get the following error, which I believe tells me that the old make file I copied over is not producing a file that is needed by the project? Am I right?
Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/home/sansari/ndk/android-ndk-r10d/ndk-build NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/sansari/AndroidStudioProjects/NDKSample/app/build/intermediates/ndk/debug/Android.mk APP_PLATFORM=android-21 NDK_OUT=/home/sansari/AndroidStudioProjects/NDKSample/app/build/intermediates/ndk/debug/obj NDK_LIBS_OUT=/home/sansari/AndroidStudioProjects/NDKSample/app/build/intermediates/ndk/debug/lib APP_ABI=all
Error Code:
2
Output:
make: *** No rule to make target `/home/sansari/AndroidStudioProjects/NDKSample/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/objs/myLib//home/sansari/AndroidStudioProjects/NDKSample/app/src/main/jni/tools/arm-eabi-4.7/lib/gcc/arm-eabi/4.7/crtn.o', needed by `/home/sansari/AndroidStudioProjects/NDKSample/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/libmyLib.so'. Stop.
Here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.sansari.ndksample"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
ndk {
moduleName ="myLib"
}
}
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:21.0.3'
}
The story behind this project is that I created it using a tutorial. In it, the author used mylib. So the error I am getting says that the make file I just moved into the JNI folder does not have a line for building mylib.so. Is that right? I looked at the make file at the root of my C code, and that does not look anything like target/dependency structure that I read about in the first few chapters of GNU make. Can you help me find the make file I need to update in order to build mylib.so?
I found some information about my question. By default build.gradle ignores the existing make files in a native project. And you have to put in your own Android.mk and Application.mk files in the Android Studio.
I found out I have to add Android.mk and application.mk to a native project in Android Studio if I am looking to port a large project into Android Studio.

Is the Android Support Library required when using Google Mobile Ads?

I'm using Android Studio and when I try to "Sync Project with Gradle Files" or "Clean Project" it fails. I see the message:
Gradle 'MyTestProject' project refresh failed:
Artifact 'com.android.support:support-v4:19.1.0:support-v4.jar' not found.
I see in my MainActivity that import com.google.android.gms.ads.*; is having a problem, saying, "Cannot resolve symbol 'android'."
I don't even know if these two are related. In the past, I have been able to add support-v4 to the dependencies, and everything was fixed. However, I am trying that again right now, and I get the same project refresh failed message.
Oh yeah... my minSdkVersion is 14, and my targetSdkVersion is 19.
Any ideas?
EDIT:
Ok, I forgot to mention that I am including the Google Play Services as a dependency, but that doesn't help. For testing, I went ahead and created a new, bare-bones, project and gradle syncs fine if I don't touch it. However, as soon as I add the Google Play Services dependency to the gradle file, I get the same fail message noted above. Here is my gradle file and that fail message once again:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:4.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Message:
Gradle 'SimpleExample' project refresh failed:
Artifact 'com.android.support:support-v4:19.0.1:support-v4.jar' not found.
I'm thinking that something else must be going on?
You need to add the Google Play Services dependency:
compile 'com.google.android.gms:play-services:4.4.52'

Resources