Android Studio Module/Dependency JDBC Issues - android

I am trying to setup a JDBC jar for my android studio project. I am currently getting an error when trying to launch the application due to the Module/Dependency I added.
Stack Trace
Error:Gradle: 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.
I tried following the steps in the trace and modifying the build.gradle file but could not resolve the issue. I am not sure if I need to uninstall and reinstall the module and set the compiler to 1.7 in the process or if I can even do that.

To get it to work you'll need a Java 7 compiled jar. See: Is it possible to use Java 8 for Android development?.
Additionally not sure why you are trying to include a JDBC driver into Android app, but recommend reading this: JDBC vs Web Service for Android

Related

Crystax usage with IntelliJ IDEA

I have tried the Crystax sample on IDEA, and I have compiled it successfully, got it to run on my phone.
However, when I try to modify the project, IDEA throws an error about Gradle version:
Error:The project is using an incompatible version of the Android Gradle "experimental" plugin.
Please update your project to use version 0.9.0.
Then I updated it and met new problems:
Gradle version 3.3 is required. Current version is 4.1.
Please fix the project's Gradle settings.
I choose to Fix Gradle wrapper and re-import project
Then the next error appears:
Cannot set readonly property: proguardFiles for class: com.android.build.gradle.managed.BuildType
Please, is there anyone who knows how to use Crystax on IDEA IDE?
I found an alternative way, which does not relies on AS to build.
Just set your system PATH to Crystax-ndk folder, set up your Application.mk and Android.mk, and run command:
ndk-build
then you will get the result lib or executable file, then, link it to your Android project.

using intellij-markdown in kotlin android project

I wanted to use intellij-markdown in one android kotlin project - but it does not survive the java roundtrip. Now I am searching for the least painful way to deal with this problem and hence ask here - perhaps someone faced the same problem. All solutions I have in mind currently are not really nice as they all diverge from upstream.
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 ':android:transformClassesWithDexForProdWithFirebaseDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: Unable to pre-dex '/home/ligi/.gradle/caches/modules-2/files-2.1/org.jetbrains/markdown/0.1.23/f02dce4ef95be9f24a6ea59de2c187f597befb70/markdown-0.1.23.jar' to '/home/ligi/git/SurvivalManual/android/build/intermediates/transforms/dex/prodWithFirebase/debug/folders/1000/10/markdown-0.1.23_4afcc7019db1f3375984c600cc493df386228117'

Compiling android application using Java 8

My application is not yet migrated to gradle, we still use Ant build script.
Recently one of our dependent libraries started using Java 8 features.
In order to compile using Java-8 lib, configured ant script to use java 1.8.
with this change, the compilation is successful, but failing in dex phase.
With 20.x build tools I got
"Bad Class File Magic (cafebabe)" error.
With 24.x build tools I got
"[dex] PARSE ERROR: unsupported class file version 52.0"
Seems to get rid of the dex error, i need to use jack toolchain, however as mentioned earlier, I am not using Gradle builds.
Is there any way to use dex with java-8 code? or Jack tools is the only solution?

Generated class list does not exist {module root}\build\intermediates\data-binding-info\release\_generated.txt

I am trying to get data binding set up in my Android project, and I am getting an error whenever I try to build. The top of the stack trace is as follows:
java.lang.RuntimeException: failure, see logs for details. Generated class list does not exist C:\git\android-lm\androidCore\build\intermediates\data-binding-info\debug\\_generated .txt
at android.databinding.tool.util.L.printMessage(L.java:100)
at android.databinding.tool.util.L.e(L.java:87)
at android.databinding.tool.util.Preconditions.check(Preconditions.java:25)
at android.databinding.tool.DataBindingBuilder.readGeneratedClasses(DataBindingBuilder.java:130)
at android.databinding.tool.DataBindingBuilder.getJarExcludeList(DataBindingBuilder.java:118)
at com.android.build.gradle.internal.LibraryTaskManager$16.getExcludeList(LibraryTaskManager.java:550)
at com.android.build.gradle.internal.tasks.LibraryJarTransform.transform(LibraryJarTransform.java:154)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:151)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:148)
at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:55)
at com.android.builder.profile.ThreadRecorder$1.record(ThreadRecorder.java:47)
at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:147)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(A nnotationProcessingTaskFactory.java:243)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(Annota tionProcessingTaskFactory.java:219)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(Ann otationProcessingTaskFactory.java:230)
Environment:
Windows 8.1
Android Studio 1.4.1 (also tried in 1.3)
Gradle plugin for Android 1.5.0-beta1
Gradle 2.4
Build tools 23.0.2
Target SDK version 23, min version 21 (also tried targeting 22)
Android Library project depending on a variety of java and other android libraries
Dagger, dbFlow with apt code generation.
I have removed all code from my project that actually uses types from the data binding libraries - just the act of enabling data binding in my build.gradle causes this error. I have tried clean and rebuild, clearing my .gradle folder, clearing all .\build folders, restarting android studio but to no avail. The error occurs both from the command line and from within AS.
Any help greatly appreciated.
Most likely, you have this block:
dataBinding {
enabled = true
}
in a module's build.gradle when there are nothing in that module that triggers databinding.

Bad class file magic or version

I already know that question has been already asked very often and answers, but no one of the answers i found fixed my problem.
It's the error:
Error:Gradle: Execution failed for task ':ffcommunity:preDexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
D:\Android SDK\sdk\build-tools\20.0.0\dx.bat --dex --output D:\Users\ReVo\Documents\IntelliJ IDEA\FFCommunity\ffcommunity\build\intermediates\pre-dexed\debug\bananaquery-2ee85432877a057e7414910b8127805535139d5d.jar D:\Users\ReVo\Documents\IntelliJ IDEA\FFCommunity\ffcommunity\libs\bananaquery.jar
Error Code:
1
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
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.processClass(Main.java:665)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
at com.android.dx.command.dexer.Main.access$600(Main.java:78)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
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:596)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
...while parsing com/comuf/revonline/bananaquery/BananaInsert.class
1 error; aborting
The error is bad class file magic (cafebabe) or version (0034.0000).
I builded and execute the application without problems many times in the same day but now this fails everytime with this message.
Project SDK is Android API 19 Platform and project level is 1.7.
CompileSDK is 19 and buildToolsVersion is '20.0.0'.
Compile options:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
and in dependencies i have:
compile files('libs/bananaquery.jar')
The library is build with SDK Android API 19 Platform with project level 1.7.
My .jar file is inside libs/ folder.
I use IntelliJ IDEA 14 Preview, it could be the reason? With IntellIJ IDEA 13 it remains stuck at "Gradle sync"
compile files could be useless since i have compile fileTree(dir: 'libs', include: ['*.jar']) too
my JAVA_HOME variable changed to Java 1.8 and I got this error message when compiling a pure java module as a dependency of my android project.
build.gradle of the java module
apply plugin: 'java'
Solution #1: Quick an dirty
I fixed it by setting my JAVA_HOME back to 1.7:
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
Solution #2: change compiler version:
change back to 1.7 for this specific module in its build.gradle
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
Ok, my bad.
In the Project SDK section, when you add an Android SDK you should provide the Java SDK and all my Android SDKs uses Java 8 as SDK so it create the class files with the wrong version even if the Project level is 1.7 (i don't know why, i supposed that everything was choosed by Project level).
Now i changed the SDK (the java version "1.x.0" part.)
and it seems to compile fine.
The reason that worked before today was because my SDK was 1.8 and not Android API x
In case people find #Marco Acierno's answer to be a bit unclear, the solution is to ensure you're building with Java 7 and not a higher version.
For Android Studio, change File -> Project Structure -> SDK Location -> JDK Location to jdk1.7.x. For the command line, ensure java -version outputs java version "1.7.x".
Setting JAVA_HOME back to 1.7 worked for me.
change all your module java version to java 1.7 in every build.grade file.
in plugin which is library and application
compileOptions{
sourceCompatibility=JavaVersion.VERSION_1_7
targetCompatibility=JavaVersion.VERSION_1_7
}
and in java
sourceCompatibility= 1.7
targetCompatibility= 1.7
This problem occurs when you use a .jar file that is not using any feature of Java 6 or higher but was built using Java 6 or higher.
If you built that .jar file then you don't need to change anything in Gradle or ProGuardor Compiler Version. The solution is very simple, just build that .jar file again but using Java 5 or less.
More details.
I had a similar issue, i solved it by upgrading my proguard.
get your proguard version by this command
java -jar ~/android-sdks/tools/proguard/lib/proguard.jar
get the latest progaurd.jar file from here (http://proguard.sourceforge.net)
replace the existing android-sdks/tools/proguard/lib/proguard.jar with new .jar file.
Hopefully this should help you.
If u using java 8 then you should upgrade to proguard 5.x coz proguard 4.x does not support java 8.
had a similar issue when i tried to add a self made library from netbeans to android studio. setting the source- and target compatibility in android studio and source/binary format in netbeans (both!) to java 1.7 solved the problem.
in android studio:
Project Structure -> Modules/App -> Propreties -> Source- and Target to 1.7
in netbeans:
File -> Project Properties -> Sources -> Source/Binary Format to 1.7
then clean and build your netbeans projekt and copy the .jar from "NBProj/dist" to "app/libs"
share the solution of the case if only Java8 installed, just set Java compiler level to 1.7 and then rebuild the project should be OK.
I got the error when using a third party library. In accordance with the above-mentioned question, it was necessary to replace the library according to the above stack trace message:
...
...while parsing com/comuf/revonline/bananaquery/BananaInsert.class
...
with the appropriate version.
Corresponding to the question, bananaquery.jar is to be replaced by the Java-compatible version.

Categories

Resources