我(再次)在项目中遇到支持库问题。我想将RenderScript库用于应用程序中的某些图像处理。这个项目是我从别人那里接手的,这是迄今为止我的第一个Android Studio / gradle项目。结果,我仍然缺乏经验,尤其是在所有那些gradle配置文件方面。
问题是:我在app模块内的build.gradle文件中包含了以下几行:
defaultConfig {
...
renderscriptTargetApi Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
renderscriptSupportModeEnabled true
...
}
在gradle.properties中,project.ANDROID_BUILD_TARGET_SDK_VERSION设置为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')
}
虚拟项目中的应用程序模块的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脚本吗?
先感谢您!
最佳答案
发布后不久,我似乎已经解决了。实际上,不同的模块确实是问题所在。将这两行添加到其他模块的gradle.build后,应用程序将编译并启动。
关于android - RenderScript包不存在-尽管已添加到build.gradle,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31806720/