Android Java: BoofCV Integration Problems - java

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

Related

Error:Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code

I have a very strange error. I use android studio 2.3.
First of all please watch my gradle file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion "28.0.2"
defaultConfig {
applicationId "com.example.name.webrtcwork"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
sourceSets.main {
jniLibs.srcDir 'libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
}
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:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.myhexaville:smart-image-picker:1.0.4'
compile 'pub.devrel:easypermissions:1.1.3'
compile('io.socket:socket.io-client:1.0.0') {
exclude group: 'org.json', module: 'json'
}
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile files('libs/autobanh.jar')
compile files('libs/base_java.jar')
compile files('libs/libjingle_peerconnection.jar')
testCompile 'junit:junit:4.12'
}
Project clean and rebuild works successfully, but if I want to run the app, I'm getting error like this.
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.
Error:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex '/Users/Hayk.Mkrtchyan/.android/build-cache/7fd66238e8a360302161a82746a2b9f0a8b83132/output/jars/classes.jar' to '/Users/Hayk.Mkrtchyan/Desktop/WebRTCWork/app/build/intermediates/pre-dexed/debug/classes_547e5465c50bca12a58d5755bafa9d6a10538b52.jar'
Ok I tried many ways to solve the issues like adding targetCompatibility = '1.7'
sourceCompatibility = '1.7' in my build file. This not works.
I don't want to add version 1.8 and I don't want to upgrade my android studio version to 3.0. How can I solve this?
And If I'll add the version 1.8 and will enable the jack, it gives error too like.
Error:Execution failed for task ':app:transformClassesWithPreJackPackagedLibrariesForDebug'.
Cannot load Jill from build tools.
How can I fix this?
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.
FYI
All com.android.support: version should be same.
Android Studio 3.0 and later supports all Java 7 language features and a subset of Java 8 language features that vary by platform version.
You can also configure it directly in the corresponding build.gradle file:
android {
...
// Configure only for each module that uses Java 8
// language features (either in its source code or
// through dependencies).
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Read Use Java 8 language features.
Thanks everyone for answer. The problem was that this library (compile 'com.myhexaville:smart-image-picker:1.0.4') gave conflict. When I removed it everything worked finally.

Cannot use lambda functions in Android with Java 1.8

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.

'java' plugin is not compatible with the Android plugins

I'm getting an error right after I installed Android studio and Created a simple app.
Steps followed:
Fresh download & installed Android studio.
Created a new project.
When the project loaded, The gradle failed with error:
Error:The 'java' plugin has been applied, but it is not compatible with the Android plugins.
Module Gradle File:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "info.ankitjc.happybirthday"
minSdkVersion 15
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(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:25.1.0'
testCompile 'junit:junit:4.12'
}
Project Gradle File:
// 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
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I searched for possible solutions here.
Android compile error; Java plugin has been applied, not compatible with android
Gradle error "Java plugin is not compatible with android plugins"
After File > Invalidate Cache/Restart
I think path has not been set as enviorment variable.
check have you declared the java sdk path . set the path as environment variable.
type "javac" in cmd(cmd must have admin previlliage).
If compile is not successfful
1 . Open the jdk location and copy the path of "bin"
2 . Open system properties in control panel.
3 . Advanced system settings -> then select "environment variables"
4 . click on "new"
5 . set variable name as "path" and variable value copied address
then try again
This means the Java plugin is being applied on top of the Android plugin. I don't see anything that stands out in your build files though. Some things to try:
Try doing a clean build from command-line. That will tell you if it's an Android Studio problem.
Create an empty app from a clean slate and see if it builds.
Update Android SDK to latest
Update Android Studio to the latest
Remove Android Studio project files and re-import
Make sure correct Java version is in your path and JAVA_HOME is set correctly
Check if there is any jars in your local lib folder that could be conflicting
Try using beta version of Android plugin compile 'com.android.tools.build:gradle:2.3.0-beta2'
I experienced this error while updating from KAPT to KSP. The docs say to add
id 'org.jetbrains.kotlin.jvm'
to the plugins block, but it appears that adding the Kotlin jvm plugin to the mix was causing my java plugin error. Remove the reference and it compiles. FYI the linked docs are more figurative than literal.
Not sure if this would help, but maybe you can try to explicitly add the java compilation option:
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
Try removing these two lines of code from your build.gradle
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
and
testCompile 'junit:junit:4.12'
Try this one
Procedure :-
1.right click on project ->Open Module Settings or F4
2.then goto SDK Location
3.after that Check on use embedded jdk(recommended)
you can see image given below
build and run project.
You can also add this in your build.gradle file
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
check if more than one jdk is installed.

Gradle build error: cannot access ITest bad class file: ITest.class default method found in version 50.0 classfile

I have strange problem and don't know how to resolve it.
I have an interface with default method, like this:
public interface ITest{
default String getText(){
return "ITest";
}
}
and class which implements this interface, like this:
public class TestClasssss implements ITest{
private String text;
}
And I trying to use this class inside my app unit tests project.
So, if I copy this classes inside my android's unit test project it compiles ok and all working as expected, however if this class and interface declared in app source folder, application do not compile and crash with
Error:(30, 10) error: cannot access ITest bad class file: ~\ITest.class
default method found in version 50.0 classfile
Please remove or make sure it appears in the correct subdirectory of the classpath.
So, how could I fix this strange behaviour?
My graddle config looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}
}
repositories {
mavenCentral()
mavenLocal()
maven {
url = "https://oss.sonatype.org/content/repositories/snapshots/"
}
jcenter()
}
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'realm-android'
apply plugin: 'com.neenbedankt.android-apt'
apt {
arguments {
androidManifestFile variant.outputs[0]?.processResources?.manifestFile
}
}
android {
compileSdkVersion 24
buildToolsVersion '24.0.1'
defaultConfig {
applicationId "io.projectname"
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
testOptions {
unitTests.returnDefaultValues = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
sourceSets {
main {
res.srcDirs =
[
'src/main/res/controls',
'src/main/res/fragments',
'src/main/res/activities',
'src/main/res/views',
'src/main/res'
]
}
}
}
ext {
JUNIT_VERSION = '4.12'
DAGGER_VERSION = '2.2'
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.0.111-beta'
testCompile "org.robolectric:robolectric:3.1.1"
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.roughike:bottom-bar:1.3.4'
compile 'com.aurelhubert:ahbottomnavigation:1.2.3'
compile 'joda-time:joda-time:2.9.4'
compile 'com.annimon:stream:1.0.9'
compile 'com.kyleduo.switchbutton:library:1.4.1'
compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.5'
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
compile('eu.davidea:flexible-adapter:5.0.0-SNAPSHOT') {
changing = true
}
compile 'com.github.aakira:expandable-layout:1.5.1#aar'
compile "cn.aigestudio.wheelpicker:WheelPicker:1.1.2"
compile 'net.sf.biweekly:biweekly:0.5.0'
//Dagger dependencies started
compile "com.google.dagger:dagger:$DAGGER_VERSION"
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
provided 'javax.annotation:jsr250-api:1.0'
compile 'javax.inject:javax.inject:1'
testCompile "junit:junit:$JUNIT_VERSION"
testApt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
//Dagger dependencies finished
provided 'org.projectlombok:lombok:1.16.10'
}
Make sure that you set up source and target compatibility correctly
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
I was dealing with the same issue, it appears to be some kind of conflict between the compiled java source version accepted on android and the output produced by the code compiled with retrolambda.
The problem raises when you use the default notation for funcional interfaces method.
There's some kind of limited support for that in the retrolambda plugin, quoting the readme of the repo (orfjackal/retrolambda):
retrolambda.defaultMethods
Whether to backport default methods and static methods on interfaces.
LIMITATIONS: All backported interfaces and all classes which implement
them or call their static methods must be backported together,
with one execution of Retrolambda.
Disabled by default. Enable by setting to "true"
So you can try using this in your android module's build.gradle file:
...
android {
...
}
retrolambda {
defaultMethods = true
}
In my case this does not work, but my scenario was quite different than yours. I was having the retrolambda code on one library project and then trying to use that on another app project.
Also I could not get the Jack & Jill compiler to work (theres some kind of java8 support with Jack enabled, see Enable Java 8 Features and the Jack Toolchain at android reference), one cryptic "NullPointer" raises at ./gradlew assembleDebug, so I suggest to avoid jackOptions for now.
Good luck!
I think that you probably need to enable the Jack compiler. You need the following:
Android Studio > 2.1
Default methods are only available if you are targetting API Level 24
Your gradle needs to look something like this:
android {
...
defaultConfig {
...
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
This is the Java 8 Language Feature Page in the Android Documentation
I had this issue after using dex2jar. According to https://gitlab.ow2.org/asm/asm/blob/master/asm/src/main/java/org/objectweb/asm/Opcodes.java#L264, version 50 of the JVM bytecode represents Java 1.6, while my dex file was designed to run on version 52 (1.8). I used another dex2jar utility (which should work on any jar, not just dex) to change the version to 1.8. The source is at https://github.com/pxb1988/dex2jar/blob/2.x/dex-tools/src/main/java/com/googlecode/dex2jar/tools/ClassVersionSwitch.java, the command is d2j-class-version-switch.sh 8 <source jar> <destination jar>.
Are you sure that your gradle build is using jdk1.8+? It seems like the build is trying to utilize a class that was built using 1.8 but being tested during build using a lower version.
try:
gradle clean build
OR
gradlew clean build
If you are using Android Studio try to Clean Project, then Build project. If it doesn't help too, then Click to File -> "Invalidate Caches / Restart". It must help

Android Studio UNEXPECTED TOP-LEVEL EXCEPTION:

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.

Categories

Resources