I want to upgrade my Android Plugin for Gradle from 2.3.3 to 3.0.1. I could fix all the errors following the Migration Guide. My problem now is that on Android Nougat (24) and Android Marshmallow (23) application icon is replaced with the default robot icon.
Could you help me find the reason for the problem. Previously icon was shown and I don't see logical reason why not now.
I tried all suggestions here without success.
Here is my Manifest file:
<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
...
<application
android:name="...Application"
android:allowBackup="false"
android:allowTaskReparenting="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/application"
android:largeHeap="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:theme="@style/Theme.MyTheme"
tools:replace="android:icon,theme,label,allowBackup">
<uses-library android:name="com.google.android.maps" />
<activity
android:name="...SplashActivity"
android:label="@string/application"
android:theme="@style/Theme.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
</application>
Here is project Gradle file:
buildscript {
ext.kotlinVersion = '1.2.10'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
allprojects {
ext {
androidApplicationId = 'myapp.android'
androidVersionCode = 1
androidVersionName = "1.0"
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}
repositories {
maven { url "https://maven.google.com" }
}
}
I found the problem in this Twitter post. "Android plugin 3.0.0 enables AAPT2 by default" as explained in the Migration guide. Looks like that this change causes problems with the resources.
To fix application's icon I had to disable the use of Aapt2 by adding
android.enableAapt2=false
ingradle.properties
file.NOTE: I could NOT reproduce the problem when I created new application with the same gradle setup.
I also wasted about 2 hours on this. The brute force solution was to create a stand-alone project and copy my assets over. From there, I spotted the solution:
Android Studio now defaults to mipmap-anydpi-v26. Previous I had mipmap-anydpi only, which worked prior to updated the gradle to 3.0+.
Hope this helps.
Android system would never show the icon for the application until you do.
Using tools:replace="attr" like you did here ->
tools:replace="android:icon,..."
Will replace the icon in the higher-priority manifest, and keep the icon in the lower-priority manifest.