1

In my app I am using GCM for push notification, we have to set 2 permission tags in the manifest of whose value I am picking up from string xml

 <uses-permission android:name="@string/app_gcm_permission" />

<permission
    android:name="@string/app_gcm_permission"
    android:protectionLevel="signature" />

In the string file

<string name="app_gcm_permission">com.lift.chi.permission.C2D_MESSAGE</string>

The gradle build is successful and when I try to run the app I get the below error

error: invalid Java identifier '@string/app_gcm_permission'.
Message{kind=ERROR, text=error: invalid Java identifier '@string/app_gcm_permission'

This is happening because android studio internally converts dot to underscore due to which it throws the invalid java identifier error. Please don't give me solutions to add the permission directly in manifest rather than picking from string file.

How can I resolve this??

WISHY
  • 11,067
  • 25
  • 105
  • 197
  • have a look here https://stackoverflow.com/questions/17045784/could-i-contain-permission-name-in-string-res – AskNilesh Jul 30 '18 at 07:02

4 Answers4

1

You can't use string resource in android:name field of <uses-permission>. You will have to use predefined strings. For more details visit this link :-

Manifest Permission

Ganesh K
  • 126
  • 14
0

Try this for a quick fix

 <permission
    android:name="com.lift.chi.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
Bmbariah
  • 687
  • 2
  • 10
  • 22
0

Insted of

<uses-permission android:name="@string/app_gcm_permission" />

<permission
    android:name="@string/app_gcm_permission"
    android:protectionLevel="signature" />

do it

<uses-permission android:name="com.lift.chi.permission.C2D_MESSAGE" />

<permission
    android:name="com.lift.chi.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
Gourango Sutradhar
  • 1,461
  • 10
  • 16
0

I was able to solve it on the basis of answer on this question

Set string from gradle in manefesst

The solution code, in build gradle, ->android->defaultConfig

manifestPlaceholders = [ gcmPermission:"com.lift.chi.permission.C2D_MESSAGE"]

And in the manifest file

<uses-permission android:name="${gcmPermission}" />

<permission
    android:name="${gcmPermission}"
    android:protectionLevel="signature" />
WISHY
  • 11,067
  • 25
  • 105
  • 197