Android build.gradle fail Android studio - java

I program with Android Studio.
Error message:
Error:Execution failed for task ':app:dexRelease'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 2
And my build.grandle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "theToolcome.theTool.theTool"
minSdkVersion 15
targetSdkVersion 22
versionCode 4
versionName "1.1"
}
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:22.0.0'
compile 'com.google.android.gms:play-services-analytics:7.3.0'
}
I didn't change anything, I only added the Google analytics. What's my problem? I search also on the stackoverflow, but nothing worked for me.
I also imported the project again, but nothing helped me.

For everyone reading.
The problem was that he downloaded a sample from the internet that contained anaylitics jar file, and he also told Android Studio to compile it for him via compile 'com.google.android.gms:play-services-analytics:7.3.0' so the end effect was that there were two libraries with mostly the same classes and that failed the build.

As the official documentation states out, your applications method references have exceeded the maximum limit:
Note: If the number of method references in your app exceeds the 65K limit, your app may fail to compile. You may be able to mitigate this problem when compiling your app by specifying only the specific Google Play services APIs your app uses, instead of all of them. For information on how to do this, see Selectively compiling APIs into your executable.
Instead of importing the entire Google Play Services, you should import the part that you use.
So instead of compile 'com.google.android.gms:play-services-analytics:7.3.0' you could use compile 'com.google.android.gms:play-services-maps:7.3.0', if what you want is GoogleMap API.
Check the Analytical Table and select the part that you want, then import it and you should be fine.

Project structure > JDK Location > Change it to a 1.7 version of the jdk.

In your message log you can scroll down to errors there can you see what the error is and maybe you can solve it at yourself. Otherwise one of the forum members can maybe help if you send the error.

Related

Can't build app when I import Xerces library (exit value 1)

I cannot seem to get my app to build when I import in the Xerces library. I am already using the multidex due to previous issues and therefore I know this is all setup properly.
I have spend a couple of days now looking online and trying all sorts of versions of Xerces and tweaks to my build.gradle but cannot work out the issue. I have tried cleaning re-building, re-setting Android Studio/my PC, using a jar directly compiling and now officially out of ideas.
Below is my build.gradle setup:
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "#packageid#"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "0.8"
multiDexEnabled true
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
// compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'me.dm7.barcodescanner:zbar:1.8.4'
compile project(':rangebar-1.3')
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
compile 'com.batch.android:batch-sdk:1.5'
compile 'xerces:xercesImpl:2.11.0'
// compile files('libs/xercesImpl-2.9.1.jar')
}
I have also extended my Application already and therefore have used the following within the class:
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
However, every time I try to build I keep getting the following error:
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1
Below is the end part of my gradle build error log:
Reading program jar [C:\Documents\MobileProjects\IA\Android\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar]
Reading library jar [C:\AppData\Local\Android\sdk\build-tools\23.0.2\lib\shrinkedAndroid.jar]
Preparing output jar [C:\Documents\MobileProjects\IA\Android\app\build\intermediates\multi-dex\debug\componentClasses.jar]
Copying resources from program jar [C:\Documents\MobileProjects\IA\Android\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar]
:app:transformClassesWithMultidexlistForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\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.
BUILD FAILED
As you have tried cleaning re-building, re-setting Android Studio/my PC, using a jar directly for compiling, now I want to give you some suggestions. Hope it can help you.
Before giving suggestion, I want to tell you to go through this article first: Configuring Your App for Multidex with Gradle. Then you can follow the suggestions.
Suggestion-1:
For gradle bulid, it must be followed
dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
to pre-dex each module and produce an APK that can be tested on
Android Lollipop without time consuming dex merging processes.
You have used minSdkVersion as "minSdkVersion 18". So plase update it.
Suggestion-2:
Note: With Android Plugin for Gradle versions lower than 1.1, you need to add the following dependency for multidex-instrumentation:
dependencies {
androidTestCompile('com.android.support:multidex-instrumentation:1.0.1') {
exclude group: 'com.android.support', module: 'multidex'
}
}
Note: Use of multidex for creating a test APK is not currently supported.
Suggestion-3:
Your input jars contain multiple resource files with the same name. ProGuard continues copying the resource files as usual, skipping any files with previously used names. Once more, the warning may be an indication of some problem though, so it's advisable to remove the duplicates. A convenient way to do so is by specifying filters on the input jars. There is no option to switch off these warnings.
The standard Android build process automatically specifies the input
jars for you. There may not be an easy way to filter them to remove
these warnings. You could remove the duplicate resource files manually
from the input and the libraries.
ProGuard may terminate when it encounters parsing errors or I/O errors, or some more serious warnings:
Suggestion-4:
Problem RAM. I had similar message in my Messages Gradle Build
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 1
I didn't have free RAM on my laptop with the OS windows 8.1. I closed a few programs that I don't need. After that, I had more free RAM and my project was built in android studio.
Suggestion-5:
Some people suggested to close Android Studio and kill the java processs, which was very big (1.2 GB). Then you can run with gradle. It helps.
Suggestion-6:
Install the latest version of the build tools. Adjust your build.gradle to use
`buildToolsVersion "22.0.1"`
It helps some cases.
I see from your build.gradle that your project seems containing different modules (compile project(':rangebar-1.3')).
I had your same issue in a multi-module project of mine. The root cause was that the same library was explicitly included in more than one module.
Let's say that your project has the following strucuture:
Project
+-Module1 (includes Module2, Module3)
+-Module2 (includes Lib.jar)
+-Module3 (includes Lib.jar)
In this configuration I was getting your same error trying to compile Module1. The solution was to reconfigure modules to include Lib.jar in only one single place, like for example:
Project
+-Module1 (includes Module2, Module3)
+-Module2 (includes Module3)
+-Module3 (includes Lib.jar)

Importing JDBC into Android Studio errors

I am currently working on an Android app and I am attempting to retrieve information from a MySQL database. I am trying to use JDBC as instructed by my professors, but I keep running into problems.
I have installed the MySQL Connector/ODBC 5.3, set a CLASSPATH environment variable for the driver I am attempting to use, which is "mysql-connector-java-5.1.38-bin.jar", and I attempted to import that JAR into my project.
I have attempted to import the JAR in two ways, which are the following:
File > New Module > Import .JAR/.AAR Package > import the mysql connector JAR
Then I proceeded to go to File > Project Structure > app > Dependencies > add module dependency
The other way I have attempted to do this was by adding the JAR into the "libs" folder of my project and follow the Project structure path to add a dependency from file.
I am running the latest version of Android Studio 2.0
The build completes successfully when following either of the importing steps however when doing so I get the following error when attempting to run the app:
Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
> JSR/RET are not supported with computeFrames option
The only solution I found relevant to this was going to Android Studio Settings and turning the Instant Run option off.
After doing so I received the following error instead:
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: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_77\bin\java.exe'' finished with non-zero exit value 1
The following is my build.gradle(Module:app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
applicationId "com.example.JohnDoe.myapp" //This is not actually the name or the name of the app on there but I changed this for privacy.
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
javaMaxHeapSize "2048M"
jumboMode = true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.2.1'
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.android.support:multidex:1.0.1'
compile project(':mysql-connector-java-5.1.38-bin')
}
The following is a link to the whole gradle console output after turning "Instant Run" off: pastebin.com/5kj6Cgeb
Please advise me where to go from here to get the JDBC driver working so I can finish this project. Thank you for your time.
UPDATE 1: Apparently the latest JDBC driver is not fully compatible with Android and causes issues. I installed and imported the previous version (5.0.8) and so far the app at least runs. Will be attempting to implement the driver now and actually develop with it, at which time I will post another update on the outcome.
You should not use JDBC in Android Apps as it is targetted to high bandwith, reliable connections to a database server, something you will not achieve on a mobile device. Try to wrap your database in a REST web service instead.
I've read several times that people struggled with using JDBC in Android, it's just not built for beeing used in the Android ecosystem. Not every library is fully compatible with Android, your gradle output suggests that the "dexer" could not convert the jar file to a .dex.
Your provided gradle output show the following error:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
See this question for a possible solution. Ensure you are building with the right Java SDK.

How to add an .so file to an Android Studio 1.5 project?

This seems to be a popular problem with Android: I have a precompiled .so file that I would like to access via the JNI, but I cannot get Android Studio (in my case version 1.5) to build the project in a way that makes this file accessible. Like the other people asking this question, I hit an UnsatisfiedLinkError when calling System.loadLibrary():
static {
System.loadLibrary("NativeLib");
}
There are several questions like this one on StackOverflow, and the solutions appear to focus on two techniques, neither of which work for me:
Creating a main/jniLibs directory: Several people say that if you create a folder called /app/src/main/jniLibs and within that a folder for your target (I tried all of armeabi, armeabi-v7, and arm64-v8a), Android Studio will find the library. See also This question. If I do this, the native call in my java code remains highlighted in red with tooltip text, 'Cannot resolve corresponding JNI function Java_my_function_etc'. The tooltip reference is identical to my method call, which I generated with the javah utility.
Modifying build.gradle Another proposed solution is to point to the location of the .so file by making a modification to build.gradle. In my case, I tried setting jniLibs.srcDirs to /src/main/jniLibs, and 'jniLibs' while the .so file in question was located in /app/src/main/jniLibs/armeabi, /app/src/main/jniLibs/armeabi-v7a, and /app/src/main/jniLibs/arm64-v8a. My gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.my.application"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['jniLibs']
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile files('libs/commons-lang3-3.1.jar')
}
A third technique which appears to have emerged from a Google Groups posting in 2013 involves packaging the .so files into a jar and including the jar file in the project. I unzipped my APK file and found that the .so files are included in ./lib/armeabi, ./lib/armeabli-v7a, and ./lib/arm64-v8a. I didn't try this technique because it seems obsolete, and unnecessary since my .so files are making it into the APK.
I'm out of things to try. Is there any other technique for including a native .so in an Android Studio project? Is there anything I could have overlooked in the above two techniques? Has Android Studio changed in some critical way since the linked questions were answered?

Execution failed for task :app:compileDebugJavaWithJavac

I picked up someone else's project and when I asked AS to run the project on my AVD, it pops me an error:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId 'ca.gggolf.aminutegolf'
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
}
I don't know what to do.. Everything else works fine and the app was working a couple of years ago when it was first made.
Enable multidex for your project. Add below line to gradle defaultConfig:
multiDexEnabled true
Also add multidex dependency to gradle's dependencies :
compile 'com.android.support:multidex:1.0.1'
Check your location address of exist project. if you use special character like :
( / | \ + = * ... )
In folder and sub-folders name, you should change it and check it out.
I changed my folder name from "UI/UX" to "UiUx" and its done :)
I'm back at this question simply because it got many views.
First, thanks all for the help. I managed to run the app by creating a new project on Android Studio and importing classes one at a time while making sure the code was still fine. Maybe creating a new project added some parameters that were not present in the older version of the project.
If someone has a better explanation, feel free to answer!
Check your lib versions. In my case it was old Realm plugin that was an issue.
Sometimes this error happens to me. I don't have any java compiler errors.
And seems this issue related to the build cache of a project.
So it can be solved like this
Build/Clean Project
Build/Make Project or Build APK
Build with below command, this command will point the exact point in source code where the compilation error is getting generated.
gradlew assembleDebug --stacktrace

resource error in android studio after update: No Resource Found

After a recent update to Android Studio, we're having problems getting a project to compile that previously worked. At first we were getting the following error:
/Users/james/Development/AndroidProjects/myapp/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.0/res/values-v23/values-v23.xml
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.
I updated the sdk build target in our gradle file to 23, which made this specific issue go away, but it left us with a ton of apache.http package errors (specifically, a ton of apache packages we use for http stuff are now gone in sdk 23).
What I want to do is solve the strange resource error, but without updating to sdk 23. I don't have the time to re-write our tools library right now to use whatever new implementation of apache http components has been issued. Does anyone have any ideas?
You need to set compileSdkVersion to 23.
Since API 23 Android removed the deprecated Apache Http packages, so if you use them for server requests, you'll need to add useLibrary 'org.apache.http.legacy' to build.gradle as stated in this link:
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
...
//only if you use Apache packages
useLibrary 'org.apache.http.legacy'
}
Change the appcompat version in your build.gradle file back to 22.2.1 (or whatever you were using before).
in your projects build.gradle file...
write as below..
i have solved that error by change the appcompat version from v7.23.0.0 to v7.22.2.1..
dependencies
{
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
}
Attention, wrong answer coming!
But anyone without apache libraries or so might find
compileSdkVersion 23
buildToolsVersion "23.0.0"
//...
dependencies {
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
}
helpful, it did the trick for me.
you should change your compiledsdkversion and targetversion to 23 in the build gradle file specific to the app.Make sure you installed sdk 23, version 6.0 before this.You can watch this vid for more help.https://www.youtube.com/watch?v=pw4jKsOU7go
if u are getting errors even after downloading newest SDK and Android Studio I am a newbie: What i did was 1. Download the recent SDK (i was ) 2.Open file-Project structure (ctrl+alt+shift+S) 3. In modules select app 4.In properties tab..change compile sdk version to api 23 Android 6.0 marshmallow(latest)
make sure compile adk versionand buildtools are of same version(23)
Hope it helps someone so that he wont suffer like i did for these couple of days.
Try to match all version:
compileSdkVersion 23
buildToolsVersion '23.0.0'
targetSdkVersion 23
compile 'com.android.support:appcompat-v7:23.0.0'
It's work for me.
compileSDK should match appCompat version.
TargetSDK can still be 22 (e.g. in case you didn't update to the new permission model yet)
if you have :
/Users/james/Development/AndroidProjects/myapp/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.0/res/values-v23/values-v23.xml
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'.
error , you must change your appcompat , buildtools , sdk to 23
but , if you don't like to change it and must be in 22
do this :
compile 23
target 22
It's works just when the build.grade was changed to that:
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "blablabla"
minSdkVersion 15
targetSdkVersion 22
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:22.0.0'
}
I noticed I didn't have sdk 23 installed. So I first installed it then re-built my project. And it worked fine.
Also compilesdkVersion should be 23
First of all,
Try to check your SDK folder, for me, it was mydocuments/appdata/sdk.... etc. So basically my sdk folder was not fully downloaded, the source of this problem mainly. You have to either use another fully downloaded android sdk(including Tools section and extras that you really need) or use the eclipse sdk that you may downloaded earlier for your Eclipse android developments. Then build->clean your project once again.
Worth to try.
Upgrade to use API 23 (Android 6.0) or change back the appcompat-v7 to 22.2.2 version in Gradle. This work for me when add google play service
Method 1:
It is showing.you did not install Api 23.
So please install API 23.
Method 2:
Change the appcompat version in your build.gradle file back to 22.0.1 (or less).

Categories

Resources