本文介绍了在Android Studio中找不到符号类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个项目A和B,其中B作为项目A的模块添加.我已经在A的Gradle构建文件中添加了依赖项.现在,我可以将B的类导入A中而不会出现任何错误(在编辑器中),但是无法构建.首选项是项目B的一类.
I have two project A and B where B is added as a module of project A. I have added dependencies in A's Gradle build file. Now i can import B's class in A without any error (in editor) but can't build. Preferences is a class of project B.
Error:(22, 23) error: cannot find symbol class Preferences
A的构建文件
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).
I can successfully build the project(A) if remove the import.
推荐答案
我已经指出了问题所在.两个项目的TargetSdk version
和support package version
不相同.在用最新版本更改这些之后,我的问题就解决了.
I have pointed out the problem. TargetSdk version
and support package version
of two project are not same. After changing these with latest version, my problem is solved.
这篇关于在Android Studio中找不到符号类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!