【问题标题】:Package not found with android library module找不到带有 android 库模块的包
【发布时间】:2017-01-21 19:49:04
【问题描述】:

我在现有项目中创建了两个不同的 Android 库模块。

现在,当我尝试运行该应用程序时,它给了我一个错误,说项目中不存在所述包。这真的让我感到困惑,因为这两个模块都在那里,而且在之前只有一个库模块时,它还在工作。

此外,在 gradle 构建时它不会给出任何错误。

这是app的gradle文件:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.cl.lo"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    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.4.0'
    compile project(":ge")
    compile project(":in")
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'

}

这是在 gradle 文件中。

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    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.4.0'
    compile 'com.google.android.gms:play-services-maps:9.4.0'
    compile 'com.google.android.gms:play-services-location:9.4.0'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
}

最后这个是 ge gradle 文件:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            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.4.0'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.google.android.gms:play-services-maps:9.4.0'
}

【问题讨论】:

    标签: android android-gradle-plugin


    【解决方案1】:

    更新
    在 ge build.gradle 中删除这一行。

    minifyEnabled true
    

    Minify 会移除库中未使用的代码,因此应用无法找到它们。

    注意:ProGuard 设置应该放在 app build.gradle 中,而不是库中。


    老答案

    如果是谷歌服务相关问题,
    在应用的 build.gradle 底部添加这一行。

    apply plugin: 'com.google.gms.google-services'
    

    The Google Services Gradle Plugin

    简介
    2 为已启用的服务所需的基本库添加依赖项。此步骤要求 apply plugin: 'com.google.gms.google-services' 行位于 app/build.gradle 文件的底部,以免引入依赖冲突。你可以通过运行 ./gradlew :app:dependencies 查看这一步的结果。

    【讨论】:

    • 你是对的,删除minifyEnabled 就行了。在旁注中,我打算分发库的 aar 文件。那么在这种情况下,我应该在哪里运行 minifyEnabled
    • @driftking998 不。不要为 aar 运行 minify。它删除了所有类/方法,因为它们没有在库本身中使用。另外,保留类和方法名。
    • 注意:使用 consumerProguardFiles 在库中使用 ProGuard 配置文件。 stackoverflow.com/questions/26983248/…
    • 看到了答案,但是如果他们打算将他们的 SDK 分发给其中包含一些关键/业务逻辑组件的开发人员该怎么办?在这种情况下如何混淆代码?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    • 2017-10-11
    • 2012-07-27
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 2016-09-13
    相关资源
    最近更新 更多