0

I create an app that include a library project and runs fine. But when I add .jar to my library project app not finds this .jar and build process crashes.

These are my .gradle files:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "org.gradiant.apps"
        minSdkVersion 14
        targetSdkVersion 21
        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.1.1'
    compile project(':a')
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21
        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.1.1'
    compile(name: 'b', ext: 'jar')

}

repositories {
    flatDir {
        dirs 'libs'
    }
}

Where a is my library project and b the new .jar that I need. And in logcat appears this message:

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not find :b:.
     Searched in the following locations:
         https://jcenter.bintray.com//b//b-.pom
         https://jcenter.bintray.com//b//b-.jar
     Required by:
         NewApps:app:unspecified > NewApps:a:unspecified

How can I fix it?

Pang
  • 9,564
  • 146
  • 81
  • 122
user3086708
  • 375
  • 3
  • 17

1 Answers1

0

First, in your library project, make it sure that it is compiled in a binary format that Android apks can support. For instance, problems arise (currently for me) if the library is compiled with java 1.8, instead of java 1.7 (what Android seems to need).

For this, in your library project build.gradle file, you should add

allprojects {
 sourceCompatibility = 1.7
 targetCompatibility = 1.7
}

Now, in the Android project, the compile dependency must be added to app/build.gradle (not to the project root build.gradle), like this:

 dependencies {
 . . . 
 compile project (":aProject")
 . . .
}

And finally, you should add to the root project settings.gradle

include ":aProject"
project(":aProject").projectDir = new File (settingsDir, "../../someFolderPath/aProject");

Hope it helps.

cibercitizen1
  • 20,944
  • 16
  • 72
  • 95