apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "SOMEID"
minSdkVersion 15
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.1'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.guava:guava:18.0'
compile 'com.google.guava:guava:18.0'
compile 'com.google.guava:guava:15.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I am fairly new to android, so please be aware. The application that I have been working on was under Ant build, and now have to change to Gradle to work with other new dependencies. And now, I am getting the following errors after migration through Android Studio->Import->Projects:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK overview-frame.html
File1: /Users/taeyounglee/StudioProjects/adr-android/app/libs/ormlite-android-4.45-javadoc.jar
File2: /Users/taeyounglee/StudioProjects/adr-android/app/libs/ormlite-core-4.45-javadoc.jar
Below are the ones that are in libs folder, I even tried hard-coding the dependencies on the build.gradle as well, but didn't work out:
HockeySDK-3.5.0.jar
http-request-4.2.jar
jsr305-2.0.1.jar
libGoogleAnalyticsV2.jar
ormlite-android-4.45.jar
ormlite-android-4.45-javadoc.jar
ormlite-android-4.45-sources.jar
ormlite-core-4.45.jar
ormlite-core-4.45-javadoc.jar
ormlite-core-4.45-sources.jar
otto-1.3.4.jar
picasso-2.1.1.jar
Any suggestions on this? The app uses ormlite, and requires both .jar files, as when I tried removing either one of those, it just throws compile errors. I tried looking up online about APK overview-frame.html, but can't seem to find reasonable answer. Help much appreciated, and thanks in advance!
If you can avoid it, stop using the jars. Gradle makes pulling dependencies down from Maven or JCenter super easy. When adding libraries like this to your projects, start thinking in terms of adding the dependency via accessing JCenter or Maven instead of manually downloading and placing the jar in your project.
compile 'com.j256.ormlite:ormlite-android:4.45'
compile 'com.j256.ormlite:ormlite-core:4.45'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup:otto:1.3.8'
compile 'net.hockeyapp.android:HockeySDK:3.7.2'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.github.kevinsawicki:http-request:6.0'
Here's their associating website references:
OrmLite
Picasso
Otto
Hockey
Analytics
HTTP Request
Related
I have an old Android project made with Eclipse ADT and I'm trying to migrate it to Android Studio.
I follow several guides and howtos and maybe I have almost migrated it.
When I try to build it I get the following error:
Error:Error converting bytecode to dex:Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
I have read a lot of solutions but none seems to suit to my problem.
But maybe this answer is for my case...
Here is the Project status in Eclipse project explorer:
and here is the migrated Project in Android Studio project view:
Maybe the problem is the dependencies property of every gradle script:
app-app:
dependencies {
compile project(':androidsupportv7appcompat')
compile project(':library')
compile files('libs/android-support-v4.jar')
}
androidsupportv7appcompat:
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/android-support-v7-appcompat.jar')
}
googleplayservice_lib:
dependencies {
compile files('libs/google-play-services.jar')
}
library: (a Google Maps library for markers clustering)
dependencies {
compile project(':googleplayservices_lib')
compile files('libs/android-support-v4.jar')
}
Do you know if something could be wrong in these dependencies configurations?
Otherwise, what could be the cause?
First of all, you should remove the Support Library module from your Android Studio project. Instead add a dependency to your apps gradle build file. If your library uses components from the support library, its build file should have the proper dependencies also.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
}
Be sure to remove the Support Library JAR files from your lib's folder.
Similarly you should add a dependency for Google Play Services.
Dependency management with Gradle is one of the many advantages of moving to Android Studio. If the library module is not written by you, you should also find the correct take dependency to add to your build file instead of the module you have now.
in one of my old projects, I had to put this in the gradle file under app section
multiDexEnabled true in the default config and then add the dex options below... maybe this will help.
defaultConfig {
applicationId "xxx"
minSdkVersion 14
targetSdkVersion 24
versionCode 4
versionName "2.2"
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "2g"
}
I have the error like
"Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzpm$zza$zza.class"
What should i do to remove this error
gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.user.merchant"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
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.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.google.android.gms:play-services-appindexing:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
//compile files('libs/google-play-services.jar')
}
As #Vaiden says the issue was:
"It seems that you have at least one library already bundled with GMS"
Every time that you face a duplicate entry error run ./gradlew app:dependencies and make sure that there is no duplicated versions of a same module. For example: in my case I had:
compile 'com.google.android.gms:play-services-gcm:9.0.0'
When I tried to use firebase in my project I add it like:
compile 'com.google.firebase:firebase-core:9.+'
compile 'com.google.firebase:firebase-messaging:9.+'
That makes my app crash cause when I navigate to the: app > build > intermediates > exploded-aar > com.google.android.gms one of the folders (play-services-basement) pull a version 9.4.0 instead 9.0.0 so what I did was to unificate the versions by adding firebase like:
compile 'com.google.firebase:firebase-core:9.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.0'
In theory you can solve this too by pushing the firebase to 9.4.0 instead.
The bottom line is to try to know which things are your dependencies introducing to the app and check "WHO" is introducing the same thing to the app, once you get there try to set a specific version of that duplicated dependency.
Based from this forum, try to change the gradle inside your C:\Program Files\Android\Android Studio\gradle\ to gradle-2.10. Also, it seems unlikely that a program that is designed to run on an Android device doesn't need all of the jars. Try removing some of them.
Check this related SO questions:
TransformException duplicate entry for common.annotations.Beta
Android dependency issue with gms play services
It seems that you have at least one library already bundled with GMS.
None of the dependencies stated in your gradle build file should have it, so the culprit might be a library jar file in your libs dir. So either you have something in your libs dir you shouldn't have put there, or a library that has GMS bundled inside of it.
Did you remember to delete libs/google-play-services.jar?
What are the necessary gradle dependencies for an App Engine Backend with Google Cloud Messaging?
Currently, when you add a module like that to your Android Studio project it adds this dependency:
'compile 'com.google.android.gms:play-services:8.4.0'
However, when you run the project you get this error:
Error:Execution failed for task
':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command
'/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java''
finished with non-zero exit value 2
Someone suggested using this:
defaultConfig {
multiDexEnabled true
}
But that actually didn't work for me.
So it appears that I have to specify only the required libraries for GAE + GCM. So far I have:
compile 'com.google.android.gms:play-services-auth:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-base:8.4.0'
full list here. But that didn't work. I got this error:
E/GMPM: GoogleService failed to initialize, status: 10, Missing an
expected resource: 'R.string.google_app_id' for initializing Google
services. Possible causes are missing google-services.json or
com.google.gms.google-services gradle plugin.
So I am at a loss.
Is there some other way around this issue? What is weird is my old GAE + GCM projects work fine importing the whole google play services. Importing those older versions of google play services in my new project does not work however. So I am not sure what is going on.
EDIT: Some more information:
I did some tests.
1) Started new Android Studio project, added new google cloud module 'App Engine Java Endpoints Module'. The auto-generated build.grade (Module: app) looks like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile project(path: ':backend', configuration: 'android-endpoints')
}
Result? Compiles and runs perfectly - no problems!
2) Started new Android Studio project, added new google cloud module 'App Engine Backend with Google Cloud Messaging'. the auto-generated build.grade (Module: app) looks like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile project(path: ':backend', configuration: 'android-endpoints')
}
Result? Same crappy error I have been getting!
So it looks like the line 'compile 'com.google.android.gms:play-services:8.4.0'' is the problem. I replaced it with
'compile 'com.google.android.gms:play-services-gcm:8.4.0''
since in theory that is all I need for google cloud messaging. When I run it I get this:
12-30 14:14:16.482 10573-10573/com.myapp.myapp
E/GMPM: GoogleService failed to initialize, status: 10, Missing an
expected resource: 'R.string.google_app_id' for initializing Google
services. Possible causes are missing google-services.json or
com.google.gms.google-services gradle plugin. 12-30 14:14:16.482
10573-10573/com.myapp.myapp E/GMPM: Scheduler not
set. Not logging error/warn. 12-30 14:14:16.502
10573-10623/com.myapp.myapp E/GMPM: Uploading is
not possible. App measurement disabled
So it looks like I am missing this google-services.json file or something. I don't get what happened with Android Studio because several months ago I made a GCM enabled app the same way and that one compiles no problem. The gradle.build file of that app looks like this:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(path: ':gcm-backend', configuration: 'android-endpoints')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.ganyo:gcm-server:1.0.2'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.android.support:support-v4:22.2.0'
}
So it looks like Android Studio stopped adding the 'compile 'com.ganyo:gcm-server:1.0.2'' dependency.
So I ran a project with
'compile 'com.ganyo:gcm-server:1.0.2'
'compile 'com.google.android.gms:play-services:8.4.0'
Result? Same Execution failed error.
Ok so let's try the old play-services library in my new project:
'compile 'com.ganyo:gcm-server:1.0.2'
'compile 'com.google.android.gms:play-services:7.5.0'
Result? Same Execution failed error.
I just don't get why this isn't working out of the box like it used to...
So, this should be considered an issue with Android Studio since simply adding a module 'App Engine Backend with Google Cloud Messaging' will break the build every time on even the simplest of apps, due to the full Google Play Services dependency 'com.google.android.gms:play-services:8.4.0' being large enough to exceed the 65K DEX method limit on its own. This problem is actually documented in 'Setting Up Google Play Services'.
The solution is, as you had discovered, to manually edit your build.gradle and add only the import for GCM 'com.google.android.gms:play-services-gcm:8.4.0'. The requirement for 'google-services.json' to be added manually is normal though, since you need to generate it for your project on developers.google.com. Adding 'multiDexEnabled true' isn't a good solution, as it increases your APK size needlessly, and you still end up with duplicate dependencies.
I've created an entry on the Android issue tracker to fix the dependencies for the App Engine GCM backend module in Android Studio. Feel free to star this issue for visibility and updates.
Preliminary tests show that this works so far.
I took at a look at the google GCM sample project here: https://github.com/googlesamples/google-services/tree/master/android/gcm
And edited my gradle files. Here is what they look like now:
APP:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.me.myapp"
minSdkVersion 13
targetSdkVersion 23
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.google.android.gms:play-services-gcm:8.4.0'
testCompile 'junit:junit:4.12'
compile project(path: ':backend', configuration: 'android-endpoints')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
apply plugin: 'com.google.gms.google-services'
PROJECT:
// 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:1.5.0'
classpath 'com.google.gms:google-services:2.0.0-alpha3'
// 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
}
And also I followed this guide (see step 2) to generate a google-services.json file which I dropped into the app/ directory.
Now the app compiles and works (so far at least).
I'm really angry this doesn't work out of the box with the auto generated gradle files and that I have to hunt them down in some sample app. It didn't used to be this way just a few months ago. It worked as soon as you added the GCM module.
If anyone else has any tips/suggestions for future projects please let me know. =D
If you do get to the stage where you need to run with MultiDex enabled, there are three steps you need to do:
Enable it in your defaultConfig in Gradle as you already tried:
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
Include it in your dependencies:
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Add it to your manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
https://developer.android.com/intl/es/tools/building/multidex.html#about
But always have a good look at the dependencies you already have as it's usually not needed.
Good day.
After updating google repository in AndroidStudio, I have an issue
> Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry:
> android/support/v7/cardview/BuildConfig.class
I'm trying to exclude group android.support from play-services, it did not help.
When I started my project on another PC I have:
> Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry:
> android/support/annotation/AnimRes.class
my build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "ru.alexeyk.myevents"
minSdkVersion 14
targetSdkVersion 23
versionCode 16
versionName "1.121"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('com.github.nkzawa:socket.io-client:0.4.2') {
exclude group: 'org.json', module: 'json'
}
compile files('libs/sentry-1.1.4.jar')
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:support-annotations:23.1.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'com.github.machinarius:preferencefragment:0.1.2'
compile 'com.edmodo:cropper:1.0.1'
compile 'com.makeramen:roundedimageview:2.1.1'
compile 'org.ocpsoft.prettytime:prettytime:4.0.0.Final'
compile 'com.yandex.android:mobmetricalib:2.00#aar'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.google.android.gms:play-services-ads:8.1.0'
compile 'com.google.android.gms:play-services-analytics:8.1.0'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-gcm:8.1.0'
}
In terminal execute in root project folder:
./gradlew clean
It helped me.
AndroidStudio Menu:
Build/Clean Project
Update old dependencies
All the above not working for me.. Because I am using Facebook Ad dependency..
Incase If anybody using this dependency compile 'com.facebook.android:audience-network-sdk:4.16.0'
Try this code instead of above
compile ('com.facebook.android:audience-network-sdk:4.16.0'){
exclude group: 'com.google.android.gms'
}
Open your system command prompt/terminal -> Go to your Project folder path (root project folder ) -> Execute following command : command :- gradlew clean or ./gradlew clean
Make sure that all your gradle dependencies are of same version. -> Example :- your appcompat and recyclerview dependencies should have same version.
-> Change your gradle dependencies to same version like :-
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:recyclerview-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
-> Rebuild your project and it will work fine.
Use project root in terminal like this:-/Users/rajnish/Desktop/RankProjects/ProjectCloud
After that enter this command ./gradlew clean
It will work.
There may be different reason for reported issue, few days back also face this issue 'duplicate jar', after upgrading studio. From all stackoverflow I tried all the suggestion but nothing worked for me.
But this is for sure some duplicate jar is there, For me it was present in one library libs folder as well as project libs folder. So I removed from project libs folder as it was not required here. So be careful while updating the studio, and try to understand all the gradle error.
I got this error because I did not have the correct line in my build.gradle. I am using the org.apache.http.legacy.jar library, which requires this:
android{
useLibrary 'org.apache.http.legacy'
...
}
So check that you have everything in your gradle file that is required.
I resolved the issue by double checking the "libs" directory and removing redundant jars, even though those jars were not manually added in the dependencies.
see if their duplicate jars or dependencies your adding remove it and your error will be gone:
Eg:
if you add android:supportv4 jar and also dependency you will get the error so remove the jar error will be gone
I resolve this is by changing the version no of recyleview to recyclerview-v7:24.2.1.
Please check your dependencies and use the proper version number.
For me the issue was caused by com.google.android.exoplayer conflicting with com.facebook.android:audience-network-sdk.
I fixed the problem by excluding the exoplayer library from the audience-network-sdk :
compile ('com.facebook.android:audience-network-sdk:4.24.0') {
exclude group: 'com.google.android.exoplayer'
}
I imported an Eclipse project in Android Studio. It uses the facebook SDK. In order to import it, I had to make sure the FacebookSDK folder was in the project path. The import was successful and I was able to do a build and there were no errors. However, when I try to run the app in the simulator I get the following error:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/facebook/AccessToken$SerializationProxyV1;
From my research, this points to the fact that the com.facebook.android package resides in 2 places: in my project and in the FacebookSDK module, which is a dependency. To resolve this, my research indicates that I need to remove the package from my project and leave it in the FacebookSDK module.
I tried doing this in Android Studio by deleting the package from the Build folder (build\generated\source\r\debug\com.facebook.android). However, when I rebuild the project, it regenerates the package. So I decided to delete the package from Finder outside of Android Studio. But the same thing happens when I run a rebuild.
Please let me know what I am doing wrong, or if there is some way to exclude this package from the build, other than removing it.
By the way, in order to exclude the package from the build, I tried putting this in my project's build.gradle (which I found in an answer on stackoverflow), but the error still occurred:
configurations {
all*.exclude group: 'com.facebook.android'
}
Here's my gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId 'org.bicsi.fall2015'
minSdkVersion 14
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
configurations {
all*.exclude group: 'com.facebook.android'
}
dependencies {
compile project(':facebookSDK')
compile 'com.android.support:support-v4:19.1.0'
compile files('libs/Parse-1.3.8.jar')
compile files('libs/PushIOManager.jar')
compile files('libs/crittercism_v4_3_0_sdkonly.jar')
compile files('libs/facebooksdk.jar')
compile files('libs/httpclient-4.0.1.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile files('libs/stackmob-android-sdk-1.3.5.jar')
compile files('libs/twitter4j-core-3.0.5.jar')
}
Your issue is here:
compile project(':facebookSDK')
compile files('libs/facebooksdk.jar')
You are using the same library (may be with different version) twice.
Remove the jar from your dependency.
Also, using Android Studio and the gradle system I suggest you removing your module locally and using
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
instead of compile project(':facebookSDK')
I would recommend you to place your 'gradle.build' file, showing the dependencies part, so it would be easier to help you.
From your explanation, you are importing twice the facebook module, from the imported module and from your own build, right?
Using compile project to include module and also getting it from maven repository. Maybe something like this?
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile project(':my_project_that_contains_facebook')
}
If thats the case, you can just do the following
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile (project(':my_project_that_contains_facebook')) {
exclude module: 'com.facebook.android'
}
}