调试buildType的自定义字符串

vol*_*nde 3 android gradle

我有一个Android应用程序,我想更改调试和其他buildTypes的应用程序标签.我没有任何口味!

这是我认为它应该工作的设置: Android Studio安装程序

-src
   |-debug
      |-res
         |-values
            |-strings.xml
   |-main
      |-res
         |-values
            |-strings.xml
      |-java
      [...]
Run Code Online (Sandbox Code Playgroud)

我没有自定义源集只是一个调试buildType:

buildTypes {
    debug {
        applicationIdSuffix ".debug"

    }
}
Run Code Online (Sandbox Code Playgroud)

所以我虽然

sourceSets.debug.res.srcDirs = ['src/debug/res'] 
Run Code Online (Sandbox Code Playgroud)

会诀窍.但事实并非如此.有任何想法吗?

如何更改每个Gradle构建类型的应用程序名称不再起作用...

vol*_*nde 21

我找到了另一个甜蜜的解决方案,使用明显的占位符:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
    android:label="${applicationLabel}">
    <activity
        android:label="${applicationLabel}">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

并在您的gradle文件中:

android {
    defaultConfig {
        manifestPlaceholders = [ applicationLabel:"@string/app_name"]
    }
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            manifestPlaceholders = [ applicationLabel:"MyApp Debug"]
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


小智 8

buildTypes {
    release {
        resValue 'string', 'APP_NAME', '"My App Release"'
    }
    debug {
        resValue 'string', 'APP_NAME', '"My App Debug"'
    }
}
Run Code Online (Sandbox Code Playgroud)

值\ strings.xml中

<string name ="app_name"> @ string/APP_NAME </ string>

并在任何地方使用app_name


Gab*_*tti 4

你必须使用

   |-debug
      |-res
         |-values
            |-strings.xml
Run Code Online (Sandbox Code Playgroud)

你的图片中你有 debug/res/strings.xml

而且你也不需要它(因为它是标准,但问题不在这里)。

sourceSets.debug.res.srcDirs = ['src/debug/res'] 
Run Code Online (Sandbox Code Playgroud)