
[英]Using build types in Gradle to run same app that uses ContentProvider on one device
[英]Android Gradle: Install all build types on one device
在使用GCM,ContentProvider,AccountType时,如何配置项目以便能够在发布版本旁安装调试版本? (不使用口味)
我一直收到错误,例如: INSTALL_FAILED_CONFLICTING_PROVIDER或INSTALL_FAILED_DUPLICATE_PERMISSION
如果你只使用构建类型而不是风格( 为什么构建类型而不是风味 ),在同一设备上安装调试apk和发行版apk是棘手的
大多数博客文章要么过时(谈论packageName)要么强迫你使用flavor,因为他们提出的解决方案不支持applicationIdSuffix
而build type
不能声明applicationId
因此你需要使用flavors
我建议使用的解决方案
为此,我在Gradle文件中使用applicationIdSuffix
, manifest占位符 , BuildConfigField
和resValue
。
剩下的唯一问题是当你想为app和每种语言设置一个不同的名字时,字符串没有被设置为可翻译( bug aosp tracker )这会强制你设置abortOnError false
否则你将无法进行发布版本。
的build.gradle
project.ext {
defaultApplicationId = "com.myapp.package"
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId defaultApplicationId
manifestPlaceholders = [ applicationIdWithSuffix: "${applicationId}" ]
buildConfigField "String", "ACCOUNT_TYPE", "\"${applicationId}\""
buildConfigField "String", "AUTHORITY", "\"${applicationId}.provider\""
resValue "string", "account_type", "${applicationId}"
resValue "string", "authority", "${applicationId}.provider"
}
buildTypes {
debug {
applicationIdSuffix ".debug"
debuggable true
manifestPlaceholders = [ applicationIdWithSuffix: defaultApplicationId + ".debug" ]
buildConfigField "String", "ACCOUNT_TYPE", "\"${defaultApplicationId}.debug\""
buildConfigField "String", "AUTHORITY", "\"${defaultApplicationId}.debug.provider\""
resValue "string", "account_type", "${defaultApplicationId}.debug"
resValue "string", "authority", "${defaultApplicationId}.debug.provider"
}
}
lintOptions {
abortOnError false
}
}
AndroidManifest.xml中
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage" >
<permission
android:name="${applicationIdWithSuffix}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="${applicationIdWithSuffix}.permission.C2D_MESSAGE" />
<application
android:label="@string/app_name" >
<provider
android:name=".MyContentProvider"
android:authorities="${applicationIdWithSuffix}.provider"
android:exported="false"
android:multiprocess="true" />
</application>
</manifest>
同步适配器xml
<sync-adapter
xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="@string/authority"
android:accountType="@string/account_type"/>
帐户验证者
<account-authenticator
xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="@string/account_type"
.../>
内容提供商
我有一个常量,用于从BuildConfig获取它。
AUTHORITY = BuildConfig.AUTHORITY
帐户类型
要获取帐户类型,您也可以从BuildConfig中获取它。
BuildConfig.ACCOUNT_TYPE
多语言应用名称
如果您希望每个应用和语言使用不同的名称:
调试/值恩/ strings.xml中
<resources>
<string name="app_name">MyApp debug EN</string>
</resources>
调试/值-FR / strings.xml中
<resources>
<string name="app_name">MyApp debug FR</string>
</resources>
主/值恩/ strings.xml中
<resources>
<string name="app_name">MyApp EN</string>
</resources>
主/值-FR / strings.xml中
<resources>
<string name="app_name">MyApp FR</string>
</resources>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.