I'm developing a library for android that will be used in many applications.
The library depends on some other libraries.
For example, it uses Dagger 1.2, so if an app that will include my library will useDagger 2.0, the project won't build because of conflicts.
What can I do?
I tried Jarjar, with this workspace gradle
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'net.vrallev.gradle:jarjar-gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
this is the app gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.xxx.yyy.sdklauncherapp"
minSdkVersion 15
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':library')
compile 'com.google.dagger:dagger:2.2'
}
and this is my library gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
apply plugin: 'net.vrallev.jarjar'
jarjar {
jarJarFile 'jarjar-1.4.jar'
rules = [
'rule com.squareup.dagger.** ext.com.squareup.dagger.#1'
]
srcExcludes = ['META-INF/**']
outputName 'build_repackaged.jar'
outputDir 'libs'
ignoreJarJarResult false
}
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.android.support:support-v4:23.1.1'
jarjar 'com.squareup.dagger:dagger:1.2.2'
}
I'm working with #Beni in the same problem and we get some working solution to this problem. The bad news are related with gradle version plugin. With this solution you are tied to gradle 1.3 version because espresso gradle script we are using is looking for a task that is present in 1.3 gradle versiĆ³n and not in the following versions.
So this is not the best approach ever, but it works and solves our problem. Anyway if someone can help to not be tied to any gradle version it would be great.
I give you a link with our solution: https://github.com/GigigoGreenLabs/JarJarDagger2Example
You have similar tools to jarjar that you can use, have a look at:
https://github.com/musketyr/gradle-fatjar-plugin
Gradle shadow plugin or maven shade plugin if you are using maven.
Hope this helps!
Related
As i change my Windows OS from 8.1 to 10..After Installing windows 10,I start Installed Android Studio 1.5.1.After Installing Android Studio,I have downloaded SDK...After this the Android Studio Opens well..Then i started doing my project..I have created new project..And i am in need of including Firebase to my project..So i have Included respective dependencies for that..
build.gradle(Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.projects.ajayjayendran.sample"
minSdkVersion 15
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.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.google.firebase:firebase-core:10.2.3'
compile 'com.google.firebase:firebase-database:10.2.3'
compile 'com.google.firebase:firebase-storage:10.2.3'
compile 'com.firebaseui:firebase-ui-database:1.1.9'
}
apply plugin: 'com.google.gms.google-services'
build.gradle(Project:Sample)
// 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:3.0.0'
// 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 am getting this following Error..I know that this Question is already in Stack Overflow but it does not resolve my problem..I have lost one day..
In old Questions,they gave solution as Installing Google Repository and Google play Service in SDK Manager..Even after Installing this,I am getting this Same Error..Please anyone here Resolve my problem..
Thanks in Advance :)
Created a new project, copied your gradle files, and managed to reproduce the errors. However, I managed to make it compile smoothly after a few changes.
I don't know where you got 10.2.3 versions, but I edited the Firebase dependencies back to 10.2.4 (see versions here).
I'm presuming it's just a typo, but the Firebase UI library doesn't have a specified 1.1.9 version (see the versions here). I changed mine to 1.1.0.
After clean building the project with the changes above, it started to throw a different error. One where you have to make sure that the Compile SDK version, build tools version, and the support library versions are aligned (see this answer).
So from the above post, I edited out the compileSdkVersion to 25 and used the latest support library versions (25.x.x).
The resulting app gradle file (builds with no problems):
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.gradle.testapp2"
minSdkVersion 15
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.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:recyclerview-v7:25.1.1'
compile 'com.android.support:cardview-v7:25.1.1'
compile 'com.google.firebase:firebase-core:10.2.4'
compile 'com.google.firebase:firebase-database:10.2.4'
compile 'com.google.firebase:firebase-storage:10.2.4'
compile 'com.firebaseui:firebase-ui-database:1.1.0'
}
apply plugin: 'com.google.gms.google-services'
P.S.: It's also advisable to have your Android SDK Tools updated.
I created an Android library named "core" that use the Logger library (https://github.com/orhanobut/logger).
Here its build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
minSdkVersion 16
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'])
compile 'com.orhanobut:logger:1.15'
compile 'com.android.support:appcompat-v7:25.0.1'
testCompile 'junit:junit:4.12'
}
Then I build a .aar of core library.
I add this library as a dependency into my application, by putting the .aarcore files in the libs folder.
That's the build.gradle of my application :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.package.test"
minSdkVersion 16
targetSdkVersion 25
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile 'com.mypackage:core:1.0#aar'
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'
})
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:multidex:1.0.1'
}
As you can see I have multidex activated.
It compile just fine but at runtime, at the first call to Logger I get an exception:
stack=java.lang.NoClassDefFoundError: Failed resolution of: Lcom/orhanobut/logger/Logger;
Even if I set transitive = true
compile (com.mypackage:core:1.0#aar) {
transitive=true
}
it doesn't work.
Thank you !
I had to do a couple of things in concert to get it to work.
1) In your library project
Add the following to your project-level gradle file:
buildscript {
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}
Be sure to use the right version of the plugin for your gradle version, check here.
Add the following to your module-level gradle file:
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.YourPackage'// Doesn't have to be github, just an example
Also in this file, make sure your dependencies (the ones you want to be transitive) use api instead of implementation if you are using Gradle 3.4+. If you are using a version of Gradle <3.4, compile is the way to go. Example:
dependencies {
api 'com.google.android.gms:play-services-location:15.0.1'
}
2) In your app project (which uses the library)
Add the following to your module-level gradle file:
dependencies {
implementation('com.github.YourPackage:yourRepo:version#aar') {
transitive=true
}
}
Add the following to you project-level gradle file (but this will depend on where your library is served from, for me it's jitpack):
allprojects {
repositories {
...
maven {
url 'https://jitpack.io'
credentials { username 'yourAuthKey' }// Only for private repositories
}
}
}
Note: You shouldn't add the auth key as a string in build.gradle, put it in a property in your gradle.properties file.
Note 2: JitPack allows you to use for example development-SNAPSHOT as a version number for a gradle dependency. Android Studio caches these dependencies and will not re-download it when you push to your development branch. To overcome this, use commit hashes as version numbers during development or clear (delete) the cache files, located on Windows at ~/.gradle/caches/modules-2/metadata-x.xx/descriptors/com.github.YourPackage/yourRepo. (Needles to say, I learned this the hard way).
Hi all i am using charts library in my project a month ago it was working fine but now i have reinstalled android studio and when i build my project it gives gradle sync error.
Failed to resolve:com.github.PhilJay:MPAndroidChart:v2.1.3
I am stuck on this any suggestions how to solve this.My android studio version is 2.1
Here is project dependencies
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.app.comismv"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven {
jcenter()
url "https://jitpack.io"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.github.PhilJay:MPAndroidChart:v2.1.3'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
//compile 'com.cardiomood.android:android-widgets:0.1.1'
}
Thanks in advance
I had the same problem, here is the latest version of MPAndroidChart-v2.2.5.jar jar file.
Just put the MPAndroidChart-v2.2.5.jar inside app/libs/
and add
dependencies {
.
.
compile files('libs/MPAndroidChart-v2.2.5.jar')
}
in gradle file
I am getting this error when I Run or Debug the app but when I build or clean my project there are no errors. It sounds strange but I've wasted my 4-5 hours searching for this but nothing was helpful.
Error:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.> java.io.FileNotFoundException: C:\Users\Saeed Jassani\Downloads\AppName\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\8.4.0\jars\classes.jar (The system cannot find the path specified)
build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 9
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:support-v4:23.1.1'
}
You can fix this by using alpha6:
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha6'
}
Clean your project and add following dependencies in your project level build.gradle file
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha6'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
}
I have new clear android app. I want to add volley to my app to make HTTP request. I am developing app with Android studio using Gradle. Here is screenshot for my app:
Ass you see i am going to add volley to my app adding this line of code com.mcxiaoke.volley:library-aar:1.0.0 to build.gradle file
I tried to add Retrofit too. But it gives same type of error: Failed to resolve: bla bla bla.
So i think in my situation gradle can not sync any other library different than com.android......
And i have tried add this lines of code to my build.gradle too. but nothing is changing
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
repositories {
mavenCentral()
}
}
Please advise
Edit: After comments added build.gradle files for project and for module.
Project:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "domain.testgradle"
minSdkVersion 11
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.android.support:appcompat-v7:23.0.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
}
Volley is now published by the Android Open Source Project on jCenter:
dependencies {
compile 'com.android.volley:volley:1.0.0'
}
You can use
com.mcxiaoke.volley:library-aar:1.0.1
Or its latest version (Not aar)
compile 'com.mcxiaoke.volley:library:1.0.19'
And set
buildToolsVersion "23.0.1"
and use
'com.google.code.gson:gson:2.3'
Add this
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:+'
compile 'com.mcxiaoke.volley:library:1.0.19'
}