Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

Android Studio library "error: package does not exist"

I have created Android library as Android Studio module. Added as dependency to my root module. While coding I can import any class from library package but while I'm trying run the application I'm getting an error package some.mylibrary.project does not exist.

build.gradle root module

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}
apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.android.support:appcompat-v7:20.+'
    compile 'com.google.android.gms:play-services:5.+'
    compile project(':libraries:mylibrary')
}

android {
    compileSdkVersion 17
    buildToolsVersion "20.0.0"

    lintOptions {
        disable 'InvalidPackage'
        checkReleaseBuilds false
        abortOnError false
    }

    ***
}

build.gradle library module

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'idea'

android {
    compileSdkVersion 17
    buildToolsVersion "20.0.0"

     *****    
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

settings.gradle

include ':libraries:mylibrary'

P.S. I have to mention that the project was exported from Eclipse IDE so the project structure is different from default one.

question from:https://stackoverflow.com/questions/26422860/android-studio-library-error-package-does-not-exist

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For Android Studio 2.2.2

Yes, in library module, it can't use the apply plugin: com.android.application statement in the module definition, yes, use apply plugin: com.android.library instead. (still in lib module)

But then you have to do the following:

  1. Expose the same SDK versions in Gradle files for both modules.
  2. Right click on your projects "app" module folder and click on -> open module settings
  3. Click on the "dependencies" tab
  4. Click on the + sign to add a new dependency and select "Module Dependency"
  5. Look for the library you need and add it.

Also while naming your lib module avoid capitals.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...