我(再次)在我的项目中遇到支持库问题。我想在我的应用程序中使用RenderScript库进行一些图像处理。这个项目是我从别人手中接过的,这是我迄今为止的第一个Android Studio / gradle项目。因此,我仍然缺乏经验,特别是关于所有这些gradle配置文件。
问题是:我在应用程序模块中的build.gradle文件中包含以下行:
defaultConfig {
...
renderscriptTargetApi Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
renderscriptSupportModeEnabled true
...
}
project.ANDROID_BUILD_TARGET_SDK_VERSION已在gradle.properties中设置为15和22,这没有什么区别。
但是,每当我编译项目时,我总会得到这样的错误:
Error:(12, 39) error: package android.support.v8.renderscript does not exist
真正奇怪的是:如果我从头创建一个新项目并在app模块中的build.gradle中包含相同的两行,我可以毫无问题地使用RenderScript类。所以我认为这不是我的一般配置的问题,但必须以某种方式与项目相关。我只是不确定任何事情都会导致这样的行为并禁用包,尽管gradle脚本中的行正确。
一件可能很重要的事情让我从一开始就感到惊讶:当我第一次将这些行添加到gradle脚本并在我的类文件中创建import语句时,Android studio询问它是否应该导入一些支持库jar文件作为一个图书馆。我不知道为什么要这样做,因为据我所知,支持类不需要任何额外的设置。我同意导入它,但正如我上面所说,仍然无法找到包和类。
我项目中的完整build.gradle文件(不工作):
apply plugin: 'com.android.application'
android {
compileSdkVersion Integer.parseInt(project.ANDROID_COMPILE_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
applicationId 'com.some.app'
multiDexEnabled = true
renderscriptTargetApi Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
renderscriptSupportModeEnabled true
minSdkVersion Integer.parseInt(project.MIN_SDK)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
signingConfigs {
signingConfigs {
debug {
storeFile file('<some file>')
keyAlias 'xxx'
keyPassword 'xxx'
storePassword 'xxx'
}
release {
storeFile file('<some file>')
keyAlias 'xxx'
keyPassword 'xxx'
storePassword 'xxx'
}
}
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
debuggable false
jniDebuggable false
zipAlignEnabled true
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0+'
compile 'com.android.support:support-v4:22.2.0+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':firebase_plugin')
compile project(':geofire')
compile 'com.android.support:multidex:1.0.0'
compile files('libs/acra-4.5.0.jar')
}
虚拟项目中app模块的build.gradle文件( 工作):
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.self.bitmapscaletest"
minSdkVersion 15
targetSdkVersion 22
renderscriptTargetApi 15
renderscriptSupportModeEnabled true
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:22.2.0'
}
较大的项目有多个模块,这可能是个问题吗?我是否还必须调整其他模块的gradle脚本?
提前谢谢!
答案 0 :(得分:3)
发布后不久我似乎解决了它。不同的模块确实似乎是问题所在。将这两行添加到其他模块后#39; gradle.build应用程序编译并启动。