简体   繁体   English

RenderScript包不存在 - 尽管已添加到build.gradle中

[英]RenderScript package does not exist - although added to build.gradle

I'm (again) struggling with a support library issue in my project. 我(再次)在我的项目中遇到支持库问题。 I want to use the RenderScript library for some image processing within my app. 我想在我的应用程序中使用RenderScript库进行一些图像处理。 This project is one that I had taken over from someone else, and it's my first Android Studio/gradle project so far. 这个项目是我从别人手中接过的,这是我迄今为止的第一个Android Studio / gradle项目。 As a consequence I still lack experience especially regarding all those gradle configuration files. 因此,我仍然缺乏经验,特别是关于所有这些gradle配置文件。

The problem is: I have included the following lines into my build.gradle file within the app module: 问题是:我已将以下行包含在app模块中的build.gradle文件中:

defaultConfig {
    ...
    renderscriptTargetApi Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
    renderscriptSupportModeEnabled true
    ...
}

project.ANDROID_BUILD_TARGET_SDK_VERSION has been set to both, 15 and 22 within gradle.properties which made no real difference. project.ANDROID_BUILD_TARGET_SDK_VERSION已在gradle.properties中设置为15和22,这没有什么区别。

However, I always get errors like this whenever I compile the project: 但是,每当我编译项目时,我总会得到这样的错误:

Error:(12, 39) error: package android.support.v8.renderscript does not exist

The really strange thing is: If I create a new project from scratch and include the same two lines in build.gradle within the app module, I am able to use the RenderScript classes without problems. 真正奇怪的是:如果我从头创建一个新项目并在app模块中的build.gradle中包含相同的两行,我可以毫无问题地使用RenderScript类。 So I think it can't be a problem with my general configuration but has to be project related somehow. 所以我认为这不是我的一般配置的问题,但必须以某种方式与项目相关。 I'm just not sure how anything could cause such a behavior and disable the packages despite the correct lines in the gradle script. 我只是不确定任何事情都会导致这样的行为并禁用包,尽管gradle脚本中的行正确。

One thing that might be important and made me wonder right from the start: When I first added those lines to the gradle script and created the import statements in my class files, Android studio asked if it should import some support library jar file as a library. 有一件事可能很重要,让我从一开始就想知道:当我第一次将这些行添加到gradle脚本并在我的类文件中创建import语句时,Android工作室询问它是否应该将一些支持库jar文件作为库导入。 I didn't know why this should be needed as the support classes shouldn't require any additional setup as far as I know. 我不知道为什么要这样做,因为据我所知,支持类不需要任何额外的设置。 I agreed to import it, but as I said above the packages and classes still can't be found. 我同意导入它,但正如我上面所说的那样,包和类仍然无法找到。

The complete build.gradle file from my project (that does not work): 从我的项目完整的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')
}

The build.gradle file of the app module from the dummy project (which does work): 来自虚拟项目的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'
}

The larger project has multiple modules, could this be a problem? 较大的项目有多个模块,这可能是个问题吗? Do I also have to adjust the gradle scripts of those other modules? 我是否还必须调整其他模块的gradle脚本?

Thank you in advance! 先感谢您!

Shortly after posting I seem to have solved it. 发布后不久我似乎解决了它。 The different modules indeed seem to be the problem. 不同的模块确实似乎是问题所在。 After adding those two lines to the other modules' gradle.build the app compiles and launches. 将这两行添加到其他模块的gradle.build后,应用程序将编译并启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Build.Gradle中的ApplicationId如何影响我的包 - How does ApplicationId in Build.Gradle affect my package 多项目gradle构建错误:包不存在 - multiproject gradle build error: package does not exist 电容器(build.gradle 不存在/不允许操作)React app to Android 无法构建 - Capacitor (build.gradle does not exist/operation not permitted) React app to Android can't build 将Android项目添加为库(SlidingMenu)[包不存在]的Gradle错误 - Gradle error with Android project added as a library (SlidingMenu) [package does not exist] 使用“resValue”本地化通过build.gradle添加的字符串资源 - Localizing string resources added via build.gradle using “resValue” Gradle如何包含build.gradle中未包含的依赖项 - How does Gradle include a dependency not included in build.gradle .co.uk域名的build.gradle软件包名称 - build.gradle package name for a .co.uk domain name Build.Gradle 模板 - Build.Gradle Templating 在 Android Studio Arctic Fox Canary 8 中,应用程序级别 build.gradle 不生成 `allprojects` 部分并在手动添加时导致错误 - In Android Studio Arctic Fox Canary 8, the app level build.gradle does not generate `allprojects` section and causes error when manually added build.gradle的结构 - Structure of build.gradle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM