anthony
anthony

Reputation: 7733

Android Studio + Gradle: define resValue without translation, how can I do that?

When defining resources with resValue in build.gradle it is impossible to mark them as translatable="false". In XML this is possible.

Exemple:

In gradle.properties:

FACEBOOK_APP_ID="XXXXXXXXXXXXX"

In gradle:

resValue "string", "FACEBOOK_APP_ID", FACEBOOK_APP_ID

When I want to generate signed APK, there is a translation error on this string because is not translated in other language... but it's normal, I don't want to translate it.

Upvotes: 5

Views: 3293

Answers (3)

heloisasim
heloisasim

Reputation: 5016

You can add it to values/string.xml with the flag translatable="false"

<string name="facebook_app_id" translatable="false">YOUR_FACEBOOK_APP_ID</String>

Or you can add the FACEBOOK_APP_ID inside your gradle file, using resValue or buildConfigField. Something like that:

buildTypes {
    debug {
        buildConfigField "string", "facebook_app_id1", "YOUR_FACEBOOK_APP_ID"
        resValue "string", "facebook_app_id", "YOUR_FACEBOOK_APP_ID"
    }
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        buildConfigField "string", "facebook_app_id1", "YOUR_FACEBOOK_APP_ID"
        resValue "string", "facebook_app_id", "YOUR_FACEBOOK_APP_ID"
    }
}

Usages:

// buildConfigField
BuildConfig.FACEBOOK_APP_ID1

// resValue
getString(R.string.FACEBOOK_APP_ID)

Upvotes: 3

Mahmoud Alnouno
Mahmoud Alnouno

Reputation: 61

I have the same error when upload apk in google I resolved it by add translatable=false it's work with me

<String Name = "Facebook_app_id"  translatable = "false" >01234567890</String>

Upvotes: 4

arbrcr
arbrcr

Reputation: 815

Gradle doesn't support this yet. You cannot add anything similar to notranslate in your gradle file.

You can add FACEBOOK_APP_ID to exclude lint translation check. MissingTranslation

https://code.google.com/p/android/issues/detail?id=152198

Upvotes: 4

Related Questions