Android Studio 3.0 Canary 2: attribute 'android:versionCode' not found

扶醉桌前 提交于 2019-12-03 18:49:28

问题


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

回答1:


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.




回答2:


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




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


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.




回答7:


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



回答8:


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.




回答9:


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.




回答10:


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




回答11:


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




回答12:


Update Android studio to Canary 3. They solved the problem




回答13:


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.




回答14:


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




回答15:


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



来源:https://stackoverflow.com/questions/44225780/android-studio-3-0-canary-2-attribute-androidversioncode-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!