作者:宁波南诚装饰_886 | 来源:互联网 | 2023-05-25 06:18
我有两个项目A和B,其中B被添加为项目A的模块.我在A的Gradle构建文件中添加了依赖项.现在我可以在A中导入B的类而没有任何错误(在编辑器中)但无法构建.偏好是一类项目B.
错误
Error:(22, 23) error: cannot find symbol class Preferences
一个构建文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.0.0"
defaultConfig {
applicationId "com.example.A"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':B')
}
B的构建文件
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: "android-library"
android {
compileSdkVersion 18
buildToolsVersion "21.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 11
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
sourceSets.main {
jniLibs.srcDir 'src/main/jniLibs'
jni.srcDirs = [] //disable automatic ndk-build call
}
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'ndk-build.cmd', '-C', file('src/main/jni').absolutePath
} else {
commandLine '/opt/adt-bundle-linux/android-ndk-r8e/ndk-build', '-C', file('src/main/jni').absolutePath
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
如果删除导入,我可以成功构建项目(A).
1> WindRider..:
如果库(无论是本地模块还是外部依赖项)具有minifyEnabled true
,但库的ProGuard配置缺失或不正确(该类有资格通过ProGuard删除),则可能发生这种情况.这导致课程没有被编译.
一般来说,决定是否必须缩小图书馆的类应该留给图书馆的消费者.但是如果你需要强制缩小你的库,你可以设置`minifyEnabled true`但你必须确保你的ProGuard配置不会删除重要的东西.我不太确定这是否可以保证.ProGuard一直是"发布前的最后一刻"头痛的源头.
2> 小智..:
对我来说这是一个类似的问题,但在proguard conf.proguard在第一个库中处于活动状态,在第二个库中处于非活动状态.
所有build.gradle上的Copie相同的proguard conf已经解决了"找不到符号类"的错误.
我的问题是相关的 - 在buildTypes下,"minifyEnabled"在一个模块中设置为"true",在app模块中设置为"false".我在两者中都将它设置为false,现在它可以工作了.
3> shantanu..:
我已经指出了这个问题.TargetSdk version
和support package version
两个项目不一样.用最新版本更改这些后,我的问题就解决了.