Android Studio Error Message at runtime - android

Would you please explain about the error message and solution?
I was working on android studio , My task was very easy , just adding 2 numbers using a library . Last time when it run successfully , I didn't add the jar file
. But After adding the jar file , the project run no longer . When I press run , it shows the error message and stop working .
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: java.lang.RuntimeException: 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_74\bin\java.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 5.158 secs
Information:3 errors
Information:0 warnings
Information:See complete output in console
Full error message log
My Full Java and XML code
Library
project : build.gradle code
Gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.blogspot.virtualn0t3b00k.myapplication"
minSdkVersion 8
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.3.0'
compile files('libs/flanagan.jar')
}

So after downloading your code, the real error is below...
The problem is that Android can't run Java 8 compiled code, which is what the library uses if you read
The current version of Java Platform 8 used in compiling the classes in flanagan.jar is jdk1.8.0.
Also, the JAR file includes some AWT and Swing packages that aren't included in the Android SDK, so the code wouldn't compile completely, anyway.
And that would explain why you say
After adding the jar file , the project run no longer
The error
Dex: Error converting bytecode to dex:
Cause: java.lang.RuntimeException: Exception parsing classes
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:752)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)
at com.android.dx.command.dexer.Main.access$1200(Main.java:85)
at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:672)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
Caused by: 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)
... 12 more
1 error; aborting
:app:transformClassesWithDexForDebug FAILED

Add this in your build.gradle after buildTypes and before dependencies and yes don't forget to remove unused jar files and compile files(libraries).
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
}
}
Clean your project once after doing all.

Enable multidex support in build.gradle configuration.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.blogspot.virtualn0t3b00k.myapplication"
multiDexEnabled true
minSdkVersion 8
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "4g"
preDexLibraries = false
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
}
If also failed then add following code in your application class
protected void attachBaseContext(Context base)
{
super.attachBaseContext(base);
MultiDex.install(this);
}
Probably your problem will be solved.

Try adding this in build.gradle file
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
Please remove the line
compile files('libs/flanagan.jar')
from app's build.gradle file because
compile fileTree(include: ['*.jar'], dir: 'libs')
line includes the library flanagan.jar which is in libs folder.So adding
compile files('libs/flanagan.jar') is duplicating and giving the error

Related

Android Studio buildbox error java.util.zip.ZipException: duplicate entry: android/support/v4/print/PrintHelper$PrintHelperStubImpl.class

hey when i try to build my apk on android i got this error i don't what it means can you help me ? :
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/print/PrintHelper$PrintHelperStubImpl.class
here is my build.gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.frgg.apps.thetri"
minSdkVersion 14
targetSdkVersion 23
multiDexEnabled true
dexOptions {
javaMaxHeapSize "4g"
}
ndk {
moduleName "player_shared"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main {
jni.srcDirs = []// <-- disable automatic ndk-build call
}
productFlavors {
}
}
dependencies {
compile('com.google.android.gms:play-services:+') { exclude module: 'support-v4' }
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
}
Error does not show up during gradle sync. But show up when i try to build the apk
What could be the problem?
EDIT
Error: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: Error while executing java process with main class com.android.dx.command.Main with arguments {--dex --num-threads=4 --multi-dex --main-dex-list C:\Users\hotrod\Desktop\APPS\android5\app\build\intermediates\multi-dex\debug\maindexlist.txt --output C:\Users\hotrod\Desktop\APPS\android5\app\build\intermediates\transforms\dex\debug\folders\1000\1f\main C:\Users\hotrod\Desktop\APPS\android5\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}
Remove
compile('com.google.android.gms:play-services:+') { exclude module: 'support-v4' }
compile files('libs/support-v4-19.0.1.jar') //Remove from Local Drive
Use
compile 'com.android.support:support-v4:23.0.1'
compile 'com.google.android.gms:play-services:11.0.4'
FYI
Remove above library from local libs folder also
Finally, Clean-Rebuild and Run .

Build APK - ERROR - app:transformClassesWithDexForDebug

I watched so many threads here and still didnt find working solution.
When I want to BUILD APK, I get this main error:
Error: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: Error while executing
java process with main class com.android.dx.command.Main with
arguments {--dex --num-threads=4 --multi-dex --main-dex-list
C:\Users\ratik\Desktop\BUILDBOX\VOLUNTEER\STUDIO\app\build\intermediates\multi-dex\debug\maindexlist.txt
--output C:\Users\ratik\Desktop\BUILDBOX\VOLUNTEER\STUDIO\app\build\intermediates\transforms\dex\debug\folders\1000\1f\main
C:\Users\ratik\Desktop\BUILDBOX\VOLUNTEER\STUDIO\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}
There is few more errors, but then apear only sometimes, some of them:
Error: at
com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
Error: at
com.android.dx.command.dexer.Main.processFileBytes(Main.java:723)
Error: at
com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
What I tried:
In build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.biif.volunteer"
minSdkVersion 14
targetSdkVersion 25
multiDexEnabled true
ndk {
moduleName "player_shared"
}
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main {
jni.srcDirs = []// <-- disable automatic ndk-build call
}
}
dependencies {
compile ('com.google.android.gms:play-services:+'){exclude module: 'support-v4'}
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
compile ('com.android.support:multidex:1.0.1')
}
In Manifest
android:name="android.support.multidex.MultiDexApplication"
Plus I turned off Instant run (saw in one thread here).
Nothing helped :( Any ideas please? Thanks for help guys :)
I included gradle.properties file in the project with:
org.gradle.jvmargs=-Xmx10248m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
and it works.

app:transformClassesWithJarMergingForDebug'. TransformException: java.util.zip.ZipException: duplicate entry while running gradlew assembleDebug

When i run : gradlew assembleDebug command on android studio project root. Building process fails nad i get this message:
What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:
org/slf4j/impl/StaticLoggerBinder.class
In my project there are two jar files: slf4j-android-1.6.1-RC1.jar and slf4j-log4j12-1.7.21.jar. And both this jars contain two jars that includes org.sl4j.impl.StaticLoggerBinder.
Here is my gradle file content which is located on app folder:
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.ias.caniasandroid"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
jumboMode true
javaMaxHeapSize "4g"
}
productFlavors {
}
}
dependencies {
debugCompile fileTree(include: ['*.jar'], dir: 'libs')
debugCompile files('libs/commons-lang3-3.4.jar')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
}
How can i fix the problem and run gradlew assembleDebugsuccessfully without changing contents of jar files?
Just remove the below classes from slf4j-android-1.6.1-RC1 jar
org/sl4j/impl/StaticLoggerBinder.class
org/sl4j/impl/StaticMarkerBinder.class
org/sl4j/impl/StaticMDCBinder.class
You can exclude particular class from a jar in gradle dependency.
To do it, unzip a jar using the Copy task, exclude the desired class and then add a file dependency on the extracted classes.
task unzipJar(type: Copy) {
from zipTree('slf4j-android-1.6.1-RC1.jar')
into ("$buildDir/libs/slf4j") //TODO: you should update this line
include "**/*.class"
exclude "org/sl4j/impl/StaticLoggerBinder.class"
exclude "org/sl4j/impl/StaticMarkerBinder.class"
exclude "org/sl4j/impl/StaticMDCBinder.class"
}
dependencies {
compile files("$buildDir/libs/slf4j") {
builtBy "unzipJar"
}
}
Note: It does everythime when your codes are compiling.
On the other hand, if you donĀ“t want to compile the package, but if you want to compile them and exclude from your JAR you could use
jar {
exclude('org/sl4j/impl/**')
}

Gradle build error after adding appium dependency

I wish to use appium for automation testing (I'm using Android Studio for dev).I added a gradle dependency for appium.However, I am unable to run the app due to following warnings and non zero exit errors.
Warning:Dependency org.apache.httpcomponents:httpclient:4.4.1 is ignored for debug as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
And error as:
> Error:Execution failed for task ':app:preDexDebug'.
> java.lang.IllegalArgumentException: Source
> D:\Learning\GDLearning\app\build\intermediates\pre-dexed\debug\websocket-client-9.2.11.v20150529-344b13c53e6f4871f43101e675dc9239cd9ab46b.jar
> and destination
> D:\Learning\GDLearning\app\build\intermediates\pre-dexed\debug\websocket-client-9.2.11.v20150529-344b13c53e6f4871f43101e675dc9239cd9ab46b.jar
> must be different
My build.gradle file is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.gdlearning"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
packagingOptions{
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile('com.google.api-client:google-api-client-android:1.20.0') {
exclude group: 'org.apache.httpcomponents'
}
compile('com.google.apis:google-api-services-tasks:v1-rev41-1.20.0') {
exclude group: 'org.apache.httpcomponents'
}
compile 'com.google.android.gms:play-services-ads:8.3.0'
compile 'io.appium:java-client:3.2.0'
}
Any suggestion/ help would be great!I explored on SO , tried a few things but it didnt worked.
You don't need to push appium dependencies to your app Build.gradle files.
All you need to do is follow the instructions at official page.
http://appium.io/slate/en/master/?ruby#quick-start
Maybe you should:
1) Download Appium
2) Setting Evironment variables (ANDROID_HOME, JAVA_HOME, ..)
3) Play with the Appium
4) Write some test code

Execution failed for task ':app:dexDebug' on Android Studio

I didn't modified library dependencies or even build.gradle script at all, just modified some code but this error showed up suddenly while it didn't before.
>Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_15\bin\java.exe'' finished with non-zero exit value 2
I tried using --stacktrace --debug but not quite understand what I saw and it seemed the error just popped up suddenly like so
>Merged dex A (3701 defs/5082.9KiB) with dex B (266 defs/275.0KiB). Result is 3967 defs/5328.6KiB. Took 1.3s
Result compacted from 10118.4KiB to 8222.8KiB to save 1895.6KiB
Merged dex A (3967 defs/5328.6KiB) with dex B (3293 defs/2941.1KiB). Result is 7260 defs/8222.8KiB. Took 1.6s
>AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"}
Now, what could be wrong or what can I do to understand what went wrong?
This is my gradle script, for reference
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.xxx.yyy"
minSdkVersion 16
targetSdkVersion 21
versionCode 24
versionName "2.1.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "2g"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services:6.1.71'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.facebook.android:facebook-android-sdk:3.21.1'
compile 'net.simonvt.menudrawer:menudrawer:3.0.+#aar'
compile 'com.commonsware.cwac:sacklist:1.0.0'
compile 'com.commonsware.cwac:merge:1.1.+'
compile 'com.loopj.android:android-async-http:1.4.5'
compile project(':library')
}
I managed to solve it by adding multiDexEnabled true under defaultConfig section in my gradle script, don't know for sure why though.
UPDATE
It is due to 65K limit just as #clemp6r explained in the comment.

Categories

Resources