Android Studio library “error: package does not exist”

前端 未结 5 1868
轮回少年
轮回少年 2020-12-10 00:30

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 tryin

相关标签:
5条回答
  • 2020-12-10 01:08

    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.

    0 讨论(0)
  • 2020-12-10 01:14

    The answer above is somewhat lacking If you project java add in Kotlin getting get this error

    • Tools Tab Kotlin and Configure Kotlin
    • (Select Android with Gradle) after select with Modules

    Project build.gradle add

    ext.kotlin_version = ‘1.3.21’
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    

    Apps build.gradle

    apply plugin: 'kotlin-android-extensions'
    
    apply plugin: 'kotlin-android'
    

    Kotlin

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    

    Referance : https://medium.com/mindorks/enabling-kotlin-support-for-a-current-only-java-android-project-98c75e04384a

    0 讨论(0)
  • 2020-12-10 01:20

    If you have a library module, it can't use the apply plugin: 'com.android.application' statement in the module definition, or the build will silently fail as you're seeing. use apply plugin: 'com.android.library' instead.

    A bug has been filed to request that the build system fail loudly instead of silently when this happens: https://code.google.com/p/android/issues/detail?id=76725

    0 讨论(0)
  • 2020-12-10 01:28

    In build-gradle app, add this row:

    implementation project(":your_name_library_here")
    
    0 讨论(0)
  • 2020-12-10 01:34

    If you are facing this issue while using Kotlin and have

    kotlin.incremental=true
    kapt.incremental.apt=true
    

    in the gradle.properties, then you need to remove this temporarily to fix the build.

    After the successful build, you can again add these properties to speed up the build time while using Kotlin.

    Reference: https://stackoverflow.com/a/58951797/3948854

    0 讨论(0)
提交回复
热议问题