2016-11-29 128 views
0

的build.gradle(APP)包com.example.module.activity不存在

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.0" 

    defaultConfig { 
     applicationId "sampleapp.com.sampleapplication" 
     minSdkVersion 14 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     renderscriptTargetApi = 18 
     renderscriptSupportModeEnabled true 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     vectorDrawables.useSupportLibrary = true 
    } 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

ext { 
    androidSupport = '25.0.1' 
    junit = '4.12' 
    espresso = '2.2.2' 
    mockito = '2.2.26' 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile("com.android.support.test.espresso:espresso-core:$espresso", { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile "com.android.support:appcompat-v7:$androidSupport" 
    testCompile "junit:junit:$junit" 
    compile project(path: ':samplemodule') 
    testCompile "org.mockito:mockito-core:$mockito" 
} 

的build.gradle(模块)

apply plugin: 'com.android.library' 

android { 
    compileSdkVersion 25 
    buildToolsVersion '25.0.0' 

    defaultConfig { 
     minSdkVersion 14 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     renderscriptTargetApi = 18 
     renderscriptSupportModeEnabled true 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     vectorDrawables.useSupportLibrary = true 
    } 

    buildTypes { 
     release { 
      shrinkResources true 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

} 

ext { 
    androidSupportLibrary = '25.0.1' 
    espresso = '2.2.2' 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile "com.android.support:appcompat-v7:$androidSupportLibrary" 
    testCompile 'junit:junit:4.12' 
} 

我得到以下错误:

Error:(5, 45) error: package com.example.module.activity does not exist 

推荐以下所有帖子:

Android Studio library “error: package does not exist”

Why do packages from library module does not exist upon compilation, even when Android Studio shows no errors in code?

Package does not exist when refrencing a java module Android Studio 1.0.1

Package does not exist when using separate App as a dependency

我在做什么错?

+0

在您的应用程序gradle文件中,您将包名称指定为'sampleapp.com.sampleapplication'。您是否在引发错误的活动中使用相同的软件包名称?或者你在使用?我认为它也应该是'sampleapp.com.sampleapplication' –

+0

sampleapp.com.sampleapplication是主要的应用程序包,错误是模块包丢 –

回答

0

我发现了问题:

buildTypes { 
     release { 
      shrinkResources true 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

当我设置miniFyEnabled false我的问题是固定的。这太奇怪了,因为这是为发布构建类型指定的,我正在调试该应用程序。

0

正如Rohit所说,“minifyEnabled true”是有道理的。 默认情况下,似乎ProGuard会从库AAR中删除所有内容。应正确填写Proguard-rules配置文件,以便从主应用程序模块中引用类。示例:

-keep public class you.library.package.name.** { 
    public protected *; 
}