简体   繁体   中英

Android hot swap not working because of AndroidManifest.xml

I'm getting this error in the console when clicking "Apply Code Changes" in Android Studio.

Changes were not applied.
Modifications to AndroidManifest.xml require an app restart.
Manifest 'AndroidManifest.xml' was modified.

However, I am not making any changes to the AndroidManifest.xml file. I verified the AndroidManifest.xml through git and no changes were made.

I have tried updating Android Studio and Gradle to the latest version, invalidating cache and rebuilding with no luck.

I experienced this same problem, it was caused by a third party gradle plugin. To fix, try removing any gradle plugins that are run with your processManifest gradle task.

The reason apply changes is not working is when determining if apply changes can run, Android Studio looks at the merged manifest.xml file's last modified value. The gradle task process{buildVarient}Manifest when run will always update the last modified value of the merged manifest. Normally if nothing has changed in your manifest files then the task is skipped by gradle allowing apply changes to work. In my case a gradle plugin is likely causing the process manifest task to run. To debug:

  1. Build and install the app on your device as you would normally
  2. Open the "Build" pane at the bottom of android studio and toggle the view to "Code mode" (the button below the green hammer)
  3. Click the apply changes button to trigger another build
  4. In the build pane you should see something like this
Executing tasks: [:app:assembleDebug]

...

> Task :app:mergeDebugResources UP-TO-DATE
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:processDebugManifest
> Task :app:processBugsnagDebugManifest
> Task :app:processDebugResources
> Task :app:compileDebugJavaWithJavac UP-TO-DATE
> Task :app:compileDebugSources UP-TO-DATE

...

> Task :app:packageDebug
> Task :app:assembleDebug

BUILD SUCCESSFUL in 2s
132 actionable tasks: 5 executed, 127 up-to-date

Notice the app:processDebugManifest task is not marked UP-TO-DATE meaning it was run.

For me the problem was the Task :app:processBugsnagDebugManifest task which always runs by design, but also triggers the manifest to rebuild. Removing the Bugsnag gradle plugin fixed the problem for our app.

EDIT:

If your problem is with Bugsnag you can disable the plugin for build types instead of removing it entirely with:

android {
    buildTypes {
        debug {
            ...
            ext.enableBugsnag = false
        }
    }
}

Solution:

It's tied to the app's gradle. https://developer.android.com/studio/run/#instant-run Instant Run is always disabled in the debugger:

I'm assuming you already used it once for the app. Try uninstalling the app from the target device/emulator (and unplugging/stopping it) then go to File-> Invalidate Caches and Restart. Then see if it still doesn't let you.

EDIT: Make sure gradle files are updated and the versions match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM