Can't generate APK Release because of GCM Send

2019-04-06 12:04发布

问题:

I have implemented GCM (Google Cloud Messaging) in my app. Google Play Services library has auto-generated values.xml in which my senderId is :

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="gcm_defaultSenderId">123</string>
</resources>

The problem is that I have other locale, and Lint during App Release is giving me an error : Error:(3) Error: "gcm_defaultSenderId" is not translated in "fr" (French) [MissingTranslation]

Because it is automaticaly generated I can't set translable = false. How I should fix this?

回答1:

I assume that you are using Android Studio.

Had the exact same problem with Android Studio 1.4.

First thing I tried was to edit the "File - Settings - Editor - Inspections - Android Lint - Incomplete Translation" Severity Setting to something other then 'Error'.

That did not help! I still was not able to build a release APK.

I ended up 'translating' the XML as follows:

  1. in the folder .../android/res create a new language folder values-de (replace de with your language code).

  2. create a file named google-services.xml in the language folder.

  3. Insert into the xml file:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
      <string name="gcm_defaultSenderId"><YOUR_SENDERID></string>
    </resources>
    

    After that I was able to build the release.



回答2:

Add a lint.xml file in your project application root (under app/) and add the missing translations to be ignored there:

<lint>
    <issue id="MissingTranslation">
        <ignore regexp="ga_trackingId"/>
        <ignore regexp="gcm_defaultSenderId"/>
        <ignore regexp="google_app_id"/>
    </issue>
</lint>

These will now be ignored by lint - you can configure which properties to ignore, and you won't have to wait for updates from the google-services team for properties that they haven't thought of.

Lint-ing will still catch all other errors, so you can still enjoy the other features.



回答3:

Since the last update of Android Studio (1.5) I had this issue too. I solved it by updating the Google Services dependencies to the latest version.

According to this link, indeed,

This issue should be fixed with 8.3.0 Google Play Services and 1.5.0-beta2 dependency.

Hope this helps! :)


EDIT Integration: actually, while the gcm_defaultSenderId string is now generated correctly (with translatable="false" attribute), google_app_id and ga_trackingID strings, for instance, are not.

For those still having issues, I came to the conclusion that we have to wait for Google guys to fix this issue and ignore the error in the meantime by adding to the app level build.gradle file

...
android {
    lintOptions {
        abortOnError false
    }
}
...


回答4:

you will probably have another bit of autogenerated code like this:

String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                    GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

Get a valid sender id from the google cloud console then you can remove the R.string.gcm_defaultSenderId from the above code and also the gcm_defaultSenderId from the resource file.



回答5:

If you want/need upgrade to newer version of:

  • lint (androidstudio with build-in lint)
  • build tools
  • compileSdkVersion
  • gradle plugin
  • gradle
  • google-services (plugin)
  • google-services dedendencies (e.g. play-services-gcm)
  • (unfortunatelly) other dependencies if are transitivelly dependent to google-services

you need to choose wiselly versions of all these parts together. Since these all needs to be compatible together. Unfortunatelly, there is no compatibility table (the only I found is more a year old, so I do not link it here. If anybody know any please share a link).

So, solution is investigate which verstion of which part blocks anything else. Which could be nightmare, so a lot of advice is to revert to last known funcional configuration. But sooner or later we will be force to upgrade.

I checked home pages of each part to find any version info, but at last I still solve it by test-and-try method.

Here is what is functional for me:

  • androidstudio 1.5
  • build tools 23.0.2
  • compileSdkVersion 23
  • gradle plugin 1.5.0
  • gradle 2.8
  • google services plugin 1.5.0
  • google services dependencies 8.3.0
  • lucky, no other external GS dependencies (obviously all internal modules needs to use same version)