17

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')
    }
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
David
  • 906
  • 3
  • 11
  • 23
  • can you post your gradle code? – pRaNaY Oct 25 '15 at 05:56
  • @David Is this the gradle code of module or app , also the error you are getting "Warning:Dependency Lib:unspecified" shows it cannot find the lib that is why showing unspecified – Amar Oct 25 '15 at 06:07
  • as per same @Amar suggest if you developing _app_ your gradle have `apply plugin: 'com.android.application' ` else if it is `module`, your gradle have `apply plugin: 'com.android.library' ` – pRaNaY Oct 25 '15 at 06:13
  • check [this](http://stackoverflow.com/questions/31787136/include-apk-module-as-dependency-in-android-studio) – pRaNaY Oct 25 '15 at 06:19
  • @Amar ..How stupid i was. I changed apply plugin: 'com.android.library' in my app and not in module. But i have another doubt. Will library project take build?? – David Oct 25 '15 at 06:30
  • @David, can you please be more specific what was the change you made? I changed it in build.grade(Module:app), that's the only "apply plugin" I find in the project... – MorZa Feb 07 '16 at 10:45
  • @Mor Are you getting error while adding library project? – David Feb 07 '16 at 10:49
  • @David Yes, just like in your question. I try to add this to my project: https://github.com/ZieIony/MaterialRecents – MorZa Feb 07 '16 at 10:50
  • @Mor Please check that you have apply plugin: 'com.android.library' in the build.gradle of your library project. – David Feb 07 '16 at 10:53
  • @Mor Is there a specific reason you want to add the project as a library. You could simply add this 'com.github.ZieIony:MaterialRecents:d2aec46f48' in your build.gradle(Module:app) – David Feb 07 '16 at 10:56
  • @David That's exactly what I do... and I also added maven { url "https://jitpack.io" } in the repositories, just like he says, and I get this error. – MorZa Feb 07 '16 at 11:01
  • @Mor Can you post the code of you gradle file – David Feb 07 '16 at 11:24
  • 1
    Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102827/discussion-between-david-and-mor). – David Feb 07 '16 at 11:24

3 Answers3

33

"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.

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
3

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

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
2

I had the same problem and that's what solved it:

  1. importing the external project as explained here: https://www.youtube.com/watch?v=2D9lYuRECoI

  2. In my project build.gradle file added compile project(':IMPORTED_PROJECT_NAME').

  3. Only then changed in the imported project gradle file "apply plugin: com.android.application" to "apply plugin: com.android.library"and removed applicationId.

MorZa
  • 2,215
  • 18
  • 33