Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ${applicationId} in library manifest

I'm working on an SDK that uses an internal ContentProvider, I would like to use this SDK in a few projects, and declare it in the library manifest, so I've tried this:

    <provider         android:name=".core.MyContentProvider"         android:authorities="${applicationId}"         android:exported="false"/> 

What happens is the ${applicationId} is replaced with the packageName of the library and not the top apk related applicationId...

Is there a way to make sure that the launching applicationId would be placed in the android:authorities value?

like image 238
TacB0sS Avatar asked Jun 11 '15 20:06

TacB0sS


People also ask

How do I view a merge manifest file?

Inspect the merged manifest and find conflictsxml file in Android Studio, and then clicking the Merged Manifest tab at the bottom of the editor. The Merged Manifest view shows the results of the merged manifest on the left and information about each merged manifest file on the right, as shown in figure 2.

What is manifest file why it is use explain different tag of it?

Every app project must have an AndroidManifest. xml file (with precisely that name) at the root of the project source set. The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.

What tag is used for intents in manifest file?

In the manifest file, you use the <intent-filter> tag to make intent to app components.


1 Answers

Was running into the same problem with several different variants and unique IDs, and ended up going with replacing a placeholder key when Gradle is building the app, kind of like so:

Gradle 3+

android.applicationVariants.all { variant ->     variant.outputs.each { output ->         output.processManifest.doLast {             File manifestFile = file("$manifestOutputDirectory/AndroidManifest.xml")              replaceInFile(manifestFile, 'P_AUTHORITY', variant.applicationId)         }     } }  def replaceInFile(file, fromString, toString) {     def updatedContent = file.getText('UTF-8')             .replaceAll(fromString, toString)      file.write(updatedContent, 'UTF-8') } 

Gradle < 3

android.applicationVariants.all { variant ->     variant.outputs.each { output ->         output.processManifest.doLast{             replaceInManifest(output, 'P_AUTHORITY', variant.applicationId)         }     }    }  def replaceInManifest(output, fromString, toString) {     def manifestOutFile = output.processManifest.manifestOutputFile     def updatedContent = manifestOutFile.getText('UTF-8').replaceAll(fromString, toString)     manifestOutFile.write(updatedContent, 'UTF-8') } 

And then in the manifest:

<provider     android:name=".core.MyContentProvider"     android:authorities="P_AUTHORITY"     android:exported="false"/> 

That's come in handy quite a few times

like image 51
Cruceo Avatar answered Sep 22 '22 08:09

Cruceo