gpt4 book ai didi

android - 在 Gradle 中将替代资源与 Build Flavors 结合使用

转载 作者:行者123 更新时间:2023-11-29 00:16:28 25 4
gpt4 key购买 nike

我已经阅读了官方文档以及此处的其他几个问题,无论我尝试什么,我的备用资源都不会加载。请ELI5!如果我有以下产品口味

productFlavor {
flavor1 {
applicationId "com.packagename.flavor1"
}
}

我究竟应该在我的项目层次结构中的什么位置创建备用资源文件夹,以及我究竟需要如何更改我的 build.gradle 文件,以便它知道在构建特定风格时查看所述位置?文档使这听起来很简单,但我整个下午都在尝试不同的变体,但没有任何运气。我误会了什么?

编辑:build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 20
buildToolsVersion '20.0.0'

defaultConfig {
applicationId "com.example.android"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

productFlavors {
default_flavor {
resValue "string", "build_variant", "default"
resValue "string", "app_title", "Android"

}
bengals {
applicationId "com.example.Bengals"
resValue "string", "build_variant", "bengals"
resValue "string", "app_title", "Cincinnati Bengals"
}

bills {
applicationId "com.example.Bills"
resValue "string", "build_variant", "bills"
resValue "string", "app_title", "Buffalo Bills"
}

boilermakers {
applicationId "com.example.Boilermakers"
resValue "string", "build_variant", "boilermakers"
resValue "string", "app_title", "Purdue Boilermakers"
}

cardinals {
applicationId "com.example.Cardinals"
resValue "string", "build_variant", "cardinals"
resValue "string", "app_title", "Cardinals"
}

colts {
applicationId "com.example.Colts"
resValue "string", "build_variant", "colts"
resValue "string", "app_title", "Indianapolis Colts"
}
cyclones {
applicationId "com.example.Cyclones"
resValue "string", "build_variant", "cyclones"
resValue "string", "app_title", "Cincinnati Cyclones"
}

eagles {
applicationId "com.example.Eagles"
resValue "string", "build_variant", "eagles"
resValue "string", "app_title", "Philadelphia Eagles"
}

hawkeyes {
applicationId "com.example.Hawkeyes"
resValue "string", "build_variant", "hawkeyes"
resValue "string", "app_title", "Hawkeyes"
}

hoosiers {
applicationId "com.example.Hoosiers"
resValue "string", "build_variant", "hoosiers"
resValue "string", "app_title", "Indiana Hoosiers"
}

packers {
applicationId "com.example.Packers"
resValue "string", "build_variant", "packers"
resValue "string", "app_title", "Green Bay Packers"
}

test_flavor {
applicationId "com.example.test"
resValue "string", "build_variant", "test"
resValue "string", "app_title", "Dolly Test"
}

titans {
applicationId "com.example.Titans"
resValue "string", "build_variant", "titans"
resValue "string", "app_title", "Tennessee Titans"
}
}
}

dependencies {
compile 'com.android.support:support-v4:20.0.0'
compile project(':admsAppLibrary')
compile 'com.google.android.gms:play-services:5.0.89'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':volley')
compile 'com.google.code.gson:gson:2.2.4'
compile project(':Minimogrify')
compile project(':urbanairship-lib-5.0.1')
}

AndroidManifest.xml 的相关部分:

<application android:name=".Application"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

最佳答案

确保您在正确的路径中创建了文件夹。

应该是app/src/flavor1/res

为了更有意义,您的主要资源位于 src/main/res 中。

注意:这可能是一个拼写错误,但您的代码应该是 productFlavors { 而不是 productFlavor {

关于android - 在 Gradle 中将替代资源与 Build Flavors 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26555975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com