Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio Library project error

I have imported a module into my project. When i rebuilt the project , AS gave me an error saying Warning:Dependency Lib:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. I searched and changed apply plugin: 'com.android.application' to apply plugin: 'com.android.library' and also removed ApplicationId from defaultConfig. Yet i am getting this same error "Warning:Dependency Lib:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency." Can any one help me?

Here is my gradle code:

apply plugin: 'com.android.library'

    android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 12
        targetSdkVersion 23
    }
    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.0'
    compile 'com.android.support:design:23.1.0'
    compile project(':DimenLib')
    }
like image 898
David Avatar asked Oct 25 '15 05:10

David


People also ask

How to add library in Android project?

Navigate to File > Project Structure > Dependencies. In the Declared Dependencies tab, click and select Library Dependency in the dropdown. In the Add Library Dependency dialog, use the search box to find the library to add.

How to add library to classpath in Android Studio?

(In File > Project Structure ) Open the module settings and select the Dependencies tab. On the Dependencies tab, click add and select Library. In the Choose Libraries dialog, select one or more libraries and click Add Selected.

How to add zip file as library in Android Studio?

Right-click on the file that you pasted on the 'libs' folder and select the option 'Add As Library'. Then a popup will appear asking to create the library. Under 'Add to Module', select 'App'.


2 Answers

"Warning:Dependency Lib:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency."

It happens when you are trying to add a dependency which is an APK.

Using:

apply plugin: 'com.android.application'

tells Gradle to build it as an application, generating an APK.

Using:

apply plugin: 'com.android.library'

it will build as a library, generating an AAR.

In your case, it seems that you are changing the plugin in the wrong place.
It seems to be your main module.

apply plugin: 'com.android.library'

dependencies {
    compile project(':DimenLib')
}

Move the apply plugin: 'com.android.library' in your DimenLib.

like image 147
Gabriele Mariotti Avatar answered Oct 25 '22 05:10

Gabriele Mariotti


Use apply plugin: 'com.android.application' instead of apply plugin: 'com.android.library'

apply plugin: 'com.android.application' applies the Android plugin for Gradle to this build. This adds Android-specific build tasks to the top-level build tasks and makes the android {...} element available to specify Android-specific build options.

Have a look here

http://developer.android.com/tools/building/plugin-for-gradle.html

like image 22
IntelliJ Amiya Avatar answered Oct 25 '22 03:10

IntelliJ Amiya