Custom debugging lines for buildType

I have an Android application and I want to change the label of the application for debugging and other buildTypes . I have no tastes!

Here is a setting that, it seems to me, looks like this: Android Studio Setup

-src |-debug |-res |-values |-strings.xml |-main |-res |-values |-strings.xml |-java [...] 

I don't have custom sources, just debug buildType:

 buildTypes { debug { applicationIdSuffix ".debug" } } 

so though

 sourceSets.debug.res.srcDirs = ['src/debug/res'] 

would be a trick. But this is not so. Any ideas?

How to change the application name for each Gradle type the assembly type no longer works ...

+3
android gradle
Sep 25 '14 at 7:28
source share
8 answers

I found another sweet solution using manifest placeholders:

 <?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> 

and in your gradle file:

 android { defaultConfig { manifestPlaceholders = [ applicationLabel:"@string/app_name"] } buildTypes { debug { applicationIdSuffix ".debug" manifestPlaceholders = [ applicationLabel:"MyApp Debug"] } } } 
+20
Mar 25 '15 at 13:18
source share
 buildTypes { release { resValue 'string', 'APP_NAME', '"My App Release"' } debug { resValue 'string', 'APP_NAME', '"My App Debug"' } } 

value \ strings.xml

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

and use username everywhere

+7
Oct 22 '15 at 17:36
source share

You have to use

  |-debug |-res |-values |-strings.xml 

In your image you have debug / res / strings.xml

You also do not need this (because it is a standard, but there is no problem here).

 sourceSets.debug.res.srcDirs = ['src/debug/res'] 
+4
Sep 25 '14 at 9:52
source share

Forget the string.xml files. Everything can be easily configured in build.gradle.

First of all, you must save the line pointer "app_name" in the AndroidManifest file and delete all instances of "app_name" in the resource string files:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application android:label="@string/app_name"> <activity android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

Secondly, the value of the resource @ string / app_name is currently undefined. Therefore, we must apply our default definition in the build.gradle file:

 defaultConfig { applicationId "com.example.myapp" minSdkVersion 14 targetSdkVersion 22 versionCode 123423432 versionName "1.0.0" resValue 'string', 'app_name', '"My app label"' } 

Currently, app_name is defined for all build types. Assuming you want to change the application label for buildTypes , each type of assembly should be defined with a string value in the same build.gradle branch:

 buildTypes { release { resValue 'string', 'app_name', '"My app label Release"' } debug { resValue 'string', 'app_name', '"My app label Debug"' } } 

Since this resource value is set programmatically, we also need to add certain translations of lint ignore in the case of Release :

 lintOptions { disable 'MissingTranslation' } 

If you want to modify it accordingly using a set of defined Flavors (dev, qua or prd), add resValues ​​definitions to productFlavours instead of buildTypes:

 productFlavors { dev { applicationId "com.example.myapp.dev" resValue 'string', 'app_name', '"My app label Dev"' } qua { applicationId "com.example.myapp.qua" resValue 'string', 'app_name', '"My app label Qua"' } prd { applicationId "com.example.myapp.prd" resValue 'string', 'app_name', '"My app label Prd"' } } 
+4
Nov 24 '15 at 3:15
source share

You can create a line in gradle, which will also be available in xml:

 buildTypes { debug { buildConfigField "String", "app_name", "AppDebug" } release { buildConfigField "String", "app_name", "AppRelease" } 

And then use it in xml:

 android:label="@string/app_name" 

Just make sure app_name not specified in strings.xml .

+2
Mar 12 '15 at 7:42
source share

Try it.

 buildTypes { debug { applicationIdSuffix ".debug" } sourceSets.debug.resources.srcDirs = ['src/debug/res'] } 
0
Dec 05 '14 at 21:23
source share

Remember that you got rid of the directory listing inside your build.gradle application?

 sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDir 'src' // res.srcDir 'res' <--- This line should be removed assets.srcDir 'assets' 
0
Feb 16 '15 at 12:37
source share

I know this is a pretty old question, but I had the same problem and I just solved it.

You should update these codes if you have one in your build.gradle for your application.

 debug.setRoot('build-types/debug') release.setRoot('build-types/release') 

These codes automatically generate your AppName.iml and set the default debug and release directory to /build-types/debug/res , which is different from src/debug/res .

0
Mar 12 '15 at 7:26
source share



All Articles