35

I've updated Android Studio to the latest canary build and now I can't run my app.

Every time when I try to build the project I get the following error:

Error:F:\...\**app_name**\app\build\intermediates\instant-run-support\debug\slice_0\AndroidManifest.xml:2 attribute 'android:versionCode' not found

I tried to manually open the file and the attribute is clearly there:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="****"
      android:versionCode="1"
      android:versionName="1.0"
      split="lib_slice_0_apk">
</manifest>

I've tried to clean the project, invalidate cache, restart android studio but nothing helped.

This is my build.gradle (app) file:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "****"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    compile 'com.android.support:appcompat-v7:25.3.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
}
Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
123
  • 545
  • 6
  • 12

15 Answers15

16

This issue is strictly related to Instant Run. Workaround: disable it inside File -> Settings/Preferences. This will at least allow you to run your app in the Canary version of AS.

Alex Newman
  • 1,369
  • 12
  • 34
5

This bug is solved since Android Studio 3.0 Canary 6, just update android studio and all SDK components and restart Android Studio.

Tested on:

Build #AI-171.4163606, built on July 7, 2017 JRE: 1.8.0_152-release-884-b01 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0

alexpfx
  • 6,412
  • 12
  • 52
  • 88
4

Simply invalidating the caches did the job for me.

File > Invalidate Caches & Restart

No need to disable Instant Run or manually delete any build folders.

Tobias
  • 7,282
  • 6
  • 63
  • 85
3

What worked for me is a combination of what robin and SamboyCoding said.

  1. Clean Project from build menu
  2. Rebuild Project from build menu

Then I could launch the app for testing without problems.

exts
  • 9,788
  • 4
  • 19
  • 21
2

What worked for me was going into my project folder, and deleting the "build" folder, to force gradle to recompile everything. I also deleted the "gradle" folder, but had to recreate it manually because AS didn't, but I don't think it was this that fixed it.

SamboyCoding
  • 583
  • 1
  • 4
  • 10
2

I had the same. I tried either rebuild the project or change build gradle a bit(e.g change a versionName) and sync, then mostly the issue is temporarily gone.

Robin
  • 1,487
  • 4
  • 17
  • 29
2

The fastest workaround that works for me in Android Studio 3.0 Canary 2 is to add the versionCode and versionName attributes, and when the error occurs, I just change it to any other value (e.g. 1.0 to 1.1 and back). Then the app starts fine.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="com.XXX"
          android:versionCode="1"
          android:versionName="1.0">
TmTron
  • 17,012
  • 10
  • 94
  • 142
1

As for 6/9/2017 Android Studio 3.0 Canary 3 the bug still exists. After trying all mentioned ways to fix this, the one that works is to:

  1. Clean Project
  2. Build Project
  3. Disable/Re-enable Instant Run feature or
  4. Reload Android Studio.

In case of the error - suggesting to send report to Google via Help > Report Instant Run Issue.., also create a bug report in Groups. Don't forget to link this StackOverlow page - may be this way Google will fix this annoying bug fast.

0leg
  • 13,464
  • 16
  • 70
  • 94
0

I got the same problem. So I tried the stable version 2.3.1 of android studio. Then there come a question if I want to use the Android studios SDK, I select this.

Try to run the app, a Gradle error come up, which request minimum Android Studio 3.0.

I start Android Studio 3.0 C2 again, the question regarding the SDK come up again, but then the app compiles and the versionCode error was gone.

0

Clean and rebuild the project and restart android studio. It will work.

0

After cleaning and rebulding I disabled instant run and re-enabled it and the error is gone.

rakex
  • 1,999
  • 2
  • 16
  • 17
0

Update Android studio to Canary 3. They solved the problem

0

Every time I get this following error:

Error:D:\StudioProjects\yoda\app\build\intermediates\instant-run-support\debug\slice_0\AndroidManifest.xml:2 attribute 'android:versionCode' not found

I'd like to delete D:\StudioProjects\yoda\app\build folder, then select Build\Rebuild Project, and everything will become all right.

Zac
  • 1
  • 2
0

For me it was enough to delete .gradle folder in the root folder of the project

Invised
  • 31
  • 2
0

open the manifest file & close it. if still not working: rebuild, open manifest file & close it, -> RUN

OWADVL
  • 10,704
  • 7
  • 55
  • 67