我的应用程序包含名称corp.acme.app
和2种产品名称apple
和pears
。他们的构建文件在下面简洁显示。
1。模块级构建文件
// project-path/project_app/build.gradle
android {
...
defaultConfig {
applicationId('corp.acme.app')
}
flavorDimensions "crunchy"
productFlavors {
apple {
applicationIdSuffix = ".apple"
dimension "crunchy"
}
pears {
applicationIdSuffix = ".pears"
dimension "crunchy"
}
}
...
}
2。 Apple产品风味JSON文件
// project-path/project_app/src/apple/google-services.json
{
...
"client": [{
"client_info": {
"mobilesdk_app_id": "gibberish:android:gibberish",
"android_client_info": {
"package_name": "corp.acme.app.apple"
}
},
...
}]
}
第3。梨产品风味JSON文件
// project-path/project_app/src/pears/google-services.json
{
...
"client": [{
"client_info": {
"mobilesdk_app_id": "gibberish:android:gibberish",
"android_client_info": {
"package_name": "corp.acme.app.pears"
}
},
...
}]
}
我能够成功为两者生成签名的APK。但问题是它们无法同时安装。必须在安装另一个之前卸载一个。
我错过了什么吗?如何安装具有2种不同产品风格的相同应用程序?
答案 0 :(得分:-1)
让每个风格在applicationId
build.gradle
答案 1 :(得分:-1)
在您的gradle中更新以下代码
$query5 = "select * from devoir where CIN_ELEVE = '$cinE' and ID_ELV_AN_CLS = $select2 GROUP BY MODULE_DEVOIR";
$result5 = mysqli_query($con,$query5);
if(mysqli_num_rows($result5)>0)
{
echo"<table class='table table-bordered table-striped table-hover table-info'><tr>
<th>MATIERE</th>
<th>devoir1</th>
<th>devoir2</th>
<th>devoir3</th>
<th>devoir4</th>
<th>devoir5</th>
<th>AVG</th>
</tr>
";
while($rows = mysqli_fetch_assoc($result5))
{
$moduleD = $rows['MODULE_DEVOIR'];
$queryDEV = "select * from devoir inner join eleve on devoir.CIN_ELEVE = eleve.CIN_ELEVE where eleve.CIN_ELEVE = '$cinE' and MODULE_DEVOIR = '$moduleD' order by MODULE_DEVOIR";
$resultDEV = mysqli_query($con,$queryDEV);
/*to print subject name*/
echo"<tr><td>$moduleD</td>";
while($rows = mysqli_fetch_assoc($resultDEV))/*loop2*/
{
$noteDEV = $rows['NOTE_DEVOIR'];
/*to print subject mark(note)*/
echo"<td>$noteDEV</td>";
/*i add the query of average inside the loop to be with touch by all row data mark*/
$queryAVG="select avg($noteDEV) as average_devoir from devoir where MODULE_DEVOIR = '$moduleD' group by MODULE_DEVOIR ";
}
$resultAVG = mysqli_query($con,$queryAVG);
if($rows = mysqli_fetch_assoc($resultAVG))
{
if($rows = mysqli_fetch_assoc($resultAVG))
{
$avg = $rows['average_devoir'];
echo"<td>$avh</td>";
}
}
echo"</tr>";
}
echo"</table>";
}
如何访问buildConfigField和res值
buildConfigField
android {
flavorDimensions "fav1"
productFlavors {
fav1 {
applicationId "com.fav1.android"
//optional if you want to set some data based on fav type
buildConfigField 'String', 'server_url', '"http://serverurl.com"'
resValue 'string', 'access_key', 'sdgsdfgsgsdg'
resValue 'string', 'app_name', 'App Name Fav1'
}
fav2 {
applicationId "com.fav2.android"
//optional if you want to set some data based on fav type
buildConfigField 'String', 'server_url', '"http://serverurl1.com"'
resValue 'string', 'access_key', 'dfssdfsdf'
resValue 'string', 'app_name', 'App Name Fav2'
}
}
}
res值
String serverUrl=BuildConfig.server_url;
OR
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/access_key" />
<强> AppName的强>
String key=getString(R.String.key)
有时Flavors构建需要不同Flavors的不同值,例如
如果需要根据Flavors build
需要基于服务器的网址
Facebook ID,所以我们可以
从gradle中指定此类信息。
答案 2 :(得分:-1)
您需要在applicationId
文件中使用不同的build.gradle
。
编辑:
从applicationId
移除defaultConfig
:
defaultConfig {
applicationId('corp.acme.app') <-- Remove this line
}
将applicationId
添加到productFlavors
并移除applicationIdSuffix
:
productFlavors {
apple {
applicationId "corp.acme.app.apple" <-- Add this line
dimension "crunchy"
}
pears {
applicationId "corp.acme.app.pears" <-- Add this line
dimension "crunchy"
}
}
答案 3 :(得分:-1)
在模块build.gradle文件中
flavorDimensions "crunchy"
productFlavors {
apple {
applicationId 'corp.acme.app.apple'
signingConfig signingConfigs.AppleConfig
dimension "crunchy"
}
pears {
applicationId 'corp.acme.app.pears'
signingConfig signingConfigs.PearsConfig
dimension "crunchy"
}
}
当运行项目更改构建变体到相应的味道
In src folder
-create apple and pears folder
Package structure like
-src
-apple
-google-services.json
-pears
-google-services.json
-main
答案 4 :(得分:-2)
我认为你的applicationIdSuffix
工作不正常请从官方的android风格文档中读出以下链接。
警告:为了与以前的SDK工具兼容,如果未在build.gradle文件中定义applicationId属性,则构建工具将使用AndroidManifest.xml文件中的包名称作为应用程序ID。在这种情况下,重构您的包名称也会更改您的应用程序ID。
提示:如果您需要在清单文件中引用应用程序ID,则可以在任何清单属性中使用${applicationId}
占位符。在构建期间,Gradle将此标记替换为实际的应用程序ID。有关更多信息,请参阅将构建变量注入Manifest。
https://developer.android.com/studio/build/application-id.html