【问题标题】:RenderScript package does not exist - although added to build.gradleRenderScript 包不存在 - 尽管已添加到 build.gradle
【发布时间】:2015-08-04 10:22:37
【问题描述】:

我(再次)在我的项目中遇到支持库问题。我想在我的应用程序中使用 RenderScript 库进行一些图像处理。这个项目是我从别人那里接手的,也是我迄今为止的第一个 Android Studio/gradle 项目。因此,我仍然缺乏经验,尤其是在所有这些 gradle 配置文件方面。

问题是:我在 app 模块内的 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 脚本并在我的类文件中创建导入语句时,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 脚本?

提前谢谢你!

【问题讨论】:

    标签: android gradle android-support-library renderscript


    【解决方案1】:

    发布后不久,我似乎已经解决了。不同的模块确实似乎是问题所在。将这两行添加到其他模块的 gradle.build 后,应用程序编译并启动。

    【讨论】:

    • 能否说的更具体一点。
    • @RishavKumar 我现在没有设置 Android 开发环境,也不再从事这个项目。尽管如此,我认为有多个 build.gradle 文件,每个列出的模块都有一个。为了解决这个问题,我将行 renderscriptTargetApi Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION) renderscriptSupportModeEnabled true 粘贴到其中。
    猜你喜欢
    • 2012-05-16
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多