Application icon not showing after Gradle plugin u

2019-07-29 06:18发布

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" }
}
}

3条回答
成全新的幸福
2楼-- · 2019-07-29 06:35

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 in gradle.properties file.

NOTE: I could NOT reproduce the problem when I created new application with the same gradle setup.

查看更多
成全新的幸福
3楼-- · 2019-07-29 06:46

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:

enter image description here

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.

查看更多
Juvenile、少年°
4楼-- · 2019-07-29 06:52

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.

查看更多
登录 后发表回答