I was trying to create a new project which has two flavor, and the sdk is independent of app.
So I modified these build.gradle files like below:
For the android lib module: sdk:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
minSdkVersion 19
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'
}
}
productFlavors {
en
zh
}
publishNonDefault true
}
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'
testCompile 'junit:junit:4.12'
compile(name: 'HERE-sdk', ext: 'aar')
}
repositories {
flatDir {//HERE SDK
dirs 'libs'
}
mavenCentral()
}
For the android app module: app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "cn.hudplay.testgradle"
minSdkVersion 19
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'
}
}
productFlavors {
en
zh
}
}
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.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
enCompile project(path:":sdk",configuration:"enRelease")
zhCompile project(path:":sdk",configuration:"zhRelease")
//compile(name: 'HERE-sdk', ext: 'aar')//this seems to be workaround if un-blocked
}
repositories {
flatDir {//HERE SDK
dirs 'libs'
}
mavenCentral()
}
Then it told me Failed to resolve ::HERE-sdk:, and no other reasons..
I tried to move Here-sdk related gradle code to app's build.gradle, no more wrong.But I do need it in the sdk module..
What should I do..Anyone could help me?
Workaround used temporarily :
compile HERE-sdk for both app and sdk, no more wrong again. But I still feel something not right there...
Hi HERE updated the documentation maybe that help you with the issue. I had the same problem too and it worked out following these steps here:
https://github.com/heremaps/here-android-sdk-examples
What worked for me using the code above as an example (and if someone looks for a solution that works) was this approach:
copy the "\HERE-sdk\libsHERE-sdk.aar" file (dowloaded from your account on Here) to your \App\libs folder, then:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar','*.aar'])
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'
testCompile 'junit:junit:4.12'
//compile(name: 'HERE-sdk', ext: 'aar')
}
NOTE: what changes was only 2 lines:
COMMENTED -> //compile(name: 'HERE-sdk', ext: 'aar') and ADDED -> '.aar' extension to array scope here -> compile fileTree(dir: 'libs', include: ['.jar','*.aar']).
OBS: I know thi's an old question and maybe someone out there in this outside world must have already answered it, but I leave here my humble contribution. If someone wants to employ me, I'm looking for a job hehehe
I got the aar compile without error by adding by adding it from
Open Module Settings
Step 1 , add the aar into app/libs folder
Step 2, Right Click App and negative to Open Module Settings
Step 3, Click on dependencies on the left and then click on the + under Declared Dependencies
Step 4, Select the libs/HERE-sdk.aar from the drop down and then click OK
Related
Can Anyone explain me what is Version Tag for git in this, I am getting error while importing this.
apply plugin: 'com.android.application'
buildscript {
repositories {
maven { url 'https:example.com' }
jcenter()
mavenCentral()
mavenLocal()
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.jatinder.bdugame"
minSdkVersion 17
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.4.0'
compile 'com.android.support:design:23.4.0'
compile 'org.bitbucket.5elements:SmartTones-SDK:VERSION_TAG'
}
Error:
Error:(45, 13) Failed to resolve: org.bitbucket.5elements:SmartTones-SDK:VERSION_TAG
Show in File<br>Show in Project Structure dialog
What does you question have to do with Git or Maven?
It does not even have anything to do with Android, besides coming from an Android project.
You declared the compile time dependency org.bitbucket.5elements:SmartTones-SDK:VERSION_TAG which means group org.bitbucket.5elements, artifact SmartTones-SDK, version VERSION_TAG. This combination is not found in any of your declared repositories, so it fails to be resolved, just as the error tells you.
In my gradle android application when I run the application I got below error.
Error:Gradle: duplicate files during packaging of APK /home/WorkSpace/MyProject/app/build/outputs/apk/app-debug-unaligned.apk
Error:Gradle: Execution failed for task ':app:packageDebug'.
Duplicate files copied in APK META-INF/license.txt
File 1: /home/.gradle/caches/modules-2/files-2.1/org.springframework.android/spring-android-rest-template/1.0.1.RELEASE/e132d929bd181941f79b0d63edafb8a86ae6fd33/spring-android-rest-template-1.0.1.RELEASE.jar
File 2: /home/.gradle/caches/modules-2/files-2.1/org.springframework.android/spring-android-core/1.0.1.RELEASE/e68f0e8e4b636ee30c4de58953be38d9b72a5e3b/spring-android-core-1.0.1.RELEASE.jar
Below is my gradle file.
build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
apply plugin: 'com.android.application'
repositories {
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.myproject.app"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/notice.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:gridlayout-v7:23.2.0'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'joda-time:joda-time:2.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.2'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.android.support:design:23.2.0'
}
How I can solve this error? Please help me.
Add below lines in the packagingOptions and dependencies.
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
And in dependencies use as below.
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:cardview-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile('org.springframework.android:spring-android-auth:1.0.1.RELEASE') {
exclude module: 'spring-core'
}
compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'joda-time:joda-time:2.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.2'
compile 'com.google.code.gson:gson:2.6.2'
}
I think this will solve your issues.
You already have this in your build file:
packagingOptions {
exclude 'META-INF/notice.txt'
}
You can just add license.txt there as well.
i tring to run my app but the gradle give me this error
:app:transformClassesWithJarMergingForDebug FAILED Error:Execution
failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: javax/inject/Inject.class
Information:BUILD FAILED
this my AndroidMainifist.xml
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.example.mohamed.movieapp"
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.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'org.glassfish.jersey.core:jersey-client:2.22.1'
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.22.1'
}
repositories {
maven { url 'java.lang.android.support.v7.app.WindowDecoreActionBar' }
}
can any one help please
The duplication comes from jersey client. It depends on both org.glassfish.hk2.external:javax.inject and javax.inject:javax.inject.
So, you need to exclude one of them:
dependencies {
...
compile ('org.glassfish.jersey.core:jersey-client:2.22.1') {
exclude group: 'javax.inject', module: 'javax.inject'
}
...
}
I try to use org.glassfish.jersey.media:jersey-media-moxy in my project and had to apply the same exclusion for that dependency too - likely it will be the same for org.glassfish.jersey.media:jersey-media-json-jackson.
This has been happening too often and I am not sure about the reason. Would really love to know the reason behind it.
My app's gradle looks like this
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':Q-municate_core')
compile "info.hoang8f:fbutton:${rootProject.FButtonVersion}"
compile "com.google.android.gms:play-services:${rootProject.googlePlayServicesVersion}"
compile "com.soundcloud.android:android-crop:${rootProject.cropperVersion}#aar"
compile group: 'com.squareup.picasso', name: 'picasso', version: "${rootProject.picassoVersion}"
compile "com.google.guava:guava:${rootProject.guavaVersion}"
compile "com.makeramen:roundedimageview-apklib:${rootProject.roundedImageViewVersion}"
compile "se.emilsjolander:stickylistheaders:${rootProject.stickyListHeadersVersion}"
compile ('de.keyboardsurfer.android.widget:crouton:1.8.4#aar'){
exclude group: 'com.google.android', module: 'support-v4'
}
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1#aar'
compile 'com.daimajia.androidanimations:library:1.1.3#aar'
compile ('it.sephiroth.android.library:pagerslidingtabstrip:1.1.1'){
exclude group: 'com.google.android', module: 'support-v4'
exclude group: 'com.google.android', module: 'support-v7'
}
}
This builds well, but my app crashes with " java.lang.NoClassDefFoundError: com.mface.mcall.utils.Consts"and its on a completely different class. I have not even used the library that I have included. Just the "compile" statement in the app gradle and the app starts crashing.
For example this:
607-5607/mcall.mface.com.mcallandroidstudio E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.mface.mcall.utils.Consts
at com.mface.mcall.utils.ImageUtils.getImageLoaderConfiguration(ImageUtils.java:60)
at com.mface.mcall.App.initImageLoader(App.java:32)
at com.mface.mcall.App.initApplication(App.java:42)
at com.mface.mcall.App.onCreate(App.java:27)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1070)
at com.lbe.security.service.core.client.b.x.callApplicationOnCreate(Unknown Source)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4708)
at android.app.ActivityThread.access$1300(ActivityThread.java:173)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1452)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5469)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:857)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
at dalvik.system.NativeStart.main(Native Method)
If I remove the following lines all is well. I have no idea why; its good to know the reason so i can work around it. This has been happening often with different libraries for example aviary.
compile ('it.sephiroth.android.library:pagerslidingtabstrip:1.1.1'){
exclude group: 'com.google.android', module: 'support-v4'
exclude group: 'com.google.android', module: 'support-v7'
}
I have tried the following combinations too
compile 'it.sephiroth.android.library:pagerslidingtabstrip:1.1.1'
compile ('it.sephiroth.android.library:pagerslidingtabstrip:1.1.1'){
exclude group: 'com.google.android', module: 'support-v4'
}
There are no gradle errors but the app crashes.
May be am missing something here?
The full app gradle
apply plugin: 'com.android.application'
repositories {
jcenter()
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "mcall.mface.com.mcallandroidstudio"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
signingConfig signingConfigs.debug
zipAlignEnabled true
}
dexOptions{
// jumboMode = true
preDexLibraries = false
incremental true
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':Q-municate_core')
compile "info.hoang8f:fbutton:${rootProject.FButtonVersion}"
compile "com.google.android.gms:play-services:${rootProject.googlePlayServicesVersion}"
compile "com.soundcloud.android:android-crop:${rootProject.cropperVersion}#aar"
compile "com.nostra13.universalimageloader:universal-image-loader:${rootProject.universalImageLoaderVersion}"
compile group: 'com.squareup.picasso', name: 'picasso', version: "${rootProject.picassoVersion}"
compile "com.google.guava:guava:${rootProject.guavaVersion}"
compile "com.makeramen:roundedimageview-apklib:${rootProject.roundedImageViewVersion}"
compile "se.emilsjolander:stickylistheaders:${rootProject.stickyListHeadersVersion}"
compile ('de.keyboardsurfer.android.widget:crouton:1.8.4#aar'){
exclude group: 'com.google.android', module: 'support-v4'
}
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1#aar'
compile 'com.daimajia.androidanimations:library:1.1.3#aar'
compile ('it.sephiroth.android.library:pagerslidingtabstrip:1.1.1'){
exclude group: 'com.google.android', module: 'support-v4'
exclude group: 'com.google.android', module: 'support-v7'
}
}
Very simple question - how to add commons-io dependency to gradle Android project?
I tried the following
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile group: 'commons-io', name: 'commons-io', version: '2.0.1'
}
but it does not work
The error is
Gradle: A problem occurred configuring project ':LearnIt'.
Failed to notify project evaluation listener.
Could not resolve all dependencies for configuration ':LearnIt:_DebugCompile'.
> Could not find commons-io:commons-io:2.0.1.
Required by:
learnit:LearnIt:unspecified
As of now (May 2014) if you use the default generated project it is actually amazingly simple (though difficult to find instructions!
Open the second level build.gradle, and add the following line to the dependencies {:
compile "commons-io:commons-io:+"
That will get the latest version of commons-io. My complete file looks like this:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 18
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile "commons-io:commons-io:+"
}
you need to declare a repository where you want to resolve the commons-io library from (e.g. MavenCentral):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories{
mavenCentral()
}
dependencies {
compile files('libs/android-support-v4.jar')
compile group: 'commons-io', name: 'commons-io', version: '2.0.1'
}
Use gradlePlease to get the dependency.
Add the following to your app/build.gradle file:
dependencies {
compile 'org.apache.commons:commons-io:1.3.2'
}
//UPDATED
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
Update 2020 using gradle
// Home Page : https://commons.apache.org/
// IO - https://commons.apache.org/proper/commons-io/
implementation group: 'commons-io', name: 'commons-io', version: '2.7'
// String / Text
implementation group: 'org.apache.commons', name: 'commons-text', version: '1.8'