我的应用程序中有两个build.gradle(:app ,:omimhikingbook )。 :app 用于构建应用程序, omimhikingbook 用于构建库,但是单击后,请在Android Studio中运行“app” 按钮。然后将在设备上创建两个完全相同的应用程序。
the result on device的图像
我猜可能是两个文件中的 buildTypes 有一些冲突。
但是我不太确定原因以及如何调整gradle配置来解决问题。
这是(:app) build.gradle的代码
apply plugin: 'com.android.application'
...
repositories {
...
}
android {
compileSdkVersion 28
defaultConfig {
applicationId 'com.hikingbook.hikingbook'
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName '1.0'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
splits.abi {
boolean enabled = project.hasProperty('splitApk');
println ("Create separate apks: " + enabled)
enable enabled
reset()
include 'x86', 'armeabi-v7a', 'arm64-v8a', 'x86_64'
universalApk true
}
buildTypes {
debug {
debuggable true
minifyEnabled false
shrinkResources false
versionNameSuffix "-debug"
manifestPlaceholders = [crashlyticsEnabled: false, analyticsEnabled: false, performanceLogcatEnabled: false]
buildConfigField 'String', 'OFFICIAL_WEBSITE', '\"https://hikingbook.net\"'
}
release {
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
manifestPlaceholders = [crashlyticsEnabled: true, analyticsEnabled: true, performanceLogcatEnabled: true]
buildConfigField 'String', 'OFFICIAL_WEBSITE', '\"https://hikingbook.net\"'
}
}
aaptOptions {
noCompress 'txt', 'bin', 'html', 'png', 'json', 'mwm', 'ttf', 'sdf', 'ui', 'config', 'csv', 'spv'
ignoreAssetsPattern "!.svn:!.git:!.DS_Store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
...
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
...
// Omim-Hikingbook, this line will implementation (:omimhikingbook) as library
implementation project(path: ':omimhikingbook')
...
}
以及(:omimhikingbook) build.gradle的代码apply plugin: 'com.android.library'
...
project.ext.versionCodes = ['armeabi-v7a': 30, 'x86': 40, 'arm64-v8a': 50, 'x86_64' : 60]
project.ext.appId = 'com.hikingbook.hikingbook'
android {
dataBinding {
enabled = true
}
compileSdkVersion 28
buildToolsVersion "27.0.3"
defaultConfig {
vectorDrawables.useSupportLibrary = true
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
...
multiDexEnabled true
multiDexKeepFile file('../multidex-config.txt')
externalNativeBuild {
...
}
}
sourceSets.main {
...
}
flavorDimensions "default"
productFlavors {
web {
dimension "default"
versionName = android.defaultConfig.versionName + '-Web'
buildConfigField 'String', 'SUPPORT_MAIL', '"[email protected]"'
android.sourceSets.web.assets.srcDirs = ['../flavors/mwm-ttf-assets']
}
}
splits.abi {
boolean enabled = project.hasProperty('splitApk');
println ("Create separate apks: " + enabled)
enable enabled
reset()
include 'x86', 'armeabi-v7a', 'arm64-v8a', 'x86_64'
universalApk true
}
lintOptions {
abortOnError false
}
signingConfigs {
...
}
buildTypes {
debug {
versionNameSuffix '-debug'
jniDebuggable true // Enable jni debug build
zipAlignEnabled true
signingConfig signingConfigs.mapswithme
android.sourceSets.debug.setRoot('../flavors/debug')
ndk {
abiFilters "x86", "arm64-v8a"
}
}
release {
signingConfig signingConfigs.mapswithme
minifyEnabled true
proguardFile('../proguard-mwm.txt')
ndk {
abiFilters "x86", "armeabi-v7a", "arm64-v8a", "x86_64"
}
}
}
externalNativeBuild {
cmake {
...
}
}
aaptOptions {
noCompress 'txt', 'bin', 'html', 'png', 'json', 'mwm', 'ttf', 'sdf', 'ui', 'config', 'csv', 'spv'
ignoreAssetsPattern "!.svn:!.git:!.DS_Store:!*.scc:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"
}
// Enables new Java features in KitKat+ but needs Java 1.7 installed
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
...
}
}
...
}
...
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
...
}
如果有任何信息丢失或建议解决该问题。请告诉我。非常感谢~~~
-更新-
(:omimhikingbook)的AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="com.hikingbook.omimhikingbook.maps"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto">
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-feature
android:name="android.hardware.touchscreen"
android:required="true"/>
<uses-feature
android:name="android.hardware.wifi"
android:required="false"/>
<uses-feature
android:name="android.hardware.location"
android:required="false"/>
<uses-feature
android:name="android.hardware.location.network"
android:required="false"/>
<uses-feature
android:name="android.hardware.location.gps"
android:required="false"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<permission
android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE"/>
<supports-screens
android:largeScreens="true"
android:xlargeScreens="true"/>
<application
android:name=".MwmApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="false"
android:theme="@style/MwmTheme"
tools:ignore="UnusedAttribute">
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity
android:name="com.hikingbook.omimhikingbook.maps.SplashActivity"
android:label="@string/app_name">
<!-- standard "geo" scheme -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="geo"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="ge0"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="ge0.me"
android:scheme="https"/>
<data
android:host="ge0.me"
android:scheme="http"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="maps.google.com"
android:scheme="https"/>
<data
android:host="maps.google.com"
android:scheme="http"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="lead"
android:scheme="mapsme"/>
<data
android:host="lead"
android:scheme="mapswithme"/>
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="dlink.maps.me"
android:scheme="https"/>
<data
android:host="dlink.mapsme.devmail.ru"
android:scheme="https"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:scheme="mapsme"/>
</intent-filter>
<!-- API CALL -->
<intent-filter>
<action android:name="com.mapswithme.maps.api.request"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="com.mapswithme.maps.pro.action.SHOW_ON_MAP"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="com.mapswithme.maps.pro.action.BUILD_ROUTE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data
android:host="*"
android:mimeType="application/vnd.google-earth.kmz"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data
android:host="*"
android:mimeType="application/vnd.google-earth.kml+xml"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.kmz"
android:scheme="file"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.kml"
android:scheme="file"/>
</intent-filter>
</activity>
<activity
android:name="com.hikingbook.omimhikingbook.maps.DownloadResourcesLegacyActivity"
android:configChanges="orientation|screenLayout|screenSize"
android:label="@string/app_name"/>
<activity-alias
android:name="com.hikingbook.omimhikingbook.maps.DownloadResourcesActivity"
android:label="@string/app_name"
android:targetActivity="com.hikingbook.omimhikingbook.maps.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity-alias>
<activity
android:name="com.hikingbook.omimhikingbook.maps.MwmActivity"
android:launchMode="singleTask"
android:windowSoftInputMode="stateAlwaysHidden|adjustPan">
</activity>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
<category android:name="${applicationId}"/>
</intent-filter>
</receiver>
</manifest>
-结论-感谢 Saurabh Thorat 提供答案。实际原因是应用程序和库都在 AndroidManifest 中都包含此代码
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
因此,只需删除代码即可获得正确的结果。the currect result on device的图像
最佳答案
从AndroidManifest.xml
的omimhikingbook
中删除此代码:
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>