问题描述
我正在使用一个内部的ContentProvider的SDK,我想在几个项目中使用该SDK,并在库清单申报,所以我已经试过这样:
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"/>
什么情况是在 $ {}的applicationID 将被替换为库的packageName,而不是顶部的apk相关的applicationID ...
What happens is the ${applicationId} is replaced with the packageName of the library and not the top apk related applicationId...
有没有一种方法,以确保在启动的applicationID将被放置在的android:当局值
Is there a way to make sure that the launching applicationId would be placed in the android:authorities value?
推荐答案
已运行到几个不同的变种和独特的ID同样的问题,并结束了替换的占位符键时摇篮正在建设的应用程序去,有点像所以:
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:
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')
}
然后在清单:
<provider
android:name=".core.MyContentProvider"
android:authorities="P_AUTHORITY"
android:exported="false"/>
这是派上用场了好几次
That's come in handy quite a few times
这篇关于使用$ {}的applicationID在库清单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!