Android:Unable to determine application id: com.android.tools.idea.run.ApkProvisionException

Android Studio 從3.0升級到3.6+之後,安裝軟件在下方run的調試臺出現

Unable to determine application id: com.android.tools.idea.run.ApkProvisionException: No outputs for the main artifact of variant: debug。

點擊上方run的綠色箭頭按鈕,除了run調試臺,沒有任何反應

編譯正常,代碼無錯誤,在app/build/outputs/apk其實是有debug包生成的,把它拷貝到手機上,也能安裝,如果你不嫌麻煩的話。不過不能安裝就不能debug。

 

出現這個問題,是由於Android Studio升級後,他的gradle和classpath不匹配。這是一份,2015年的項目,依賴包多,代碼老化,使用的classpath是2.3.3,gradle是3.3,現在的classpath能到3.6+,gradle能5.+。想要不改動就解決的話,下載一個Android Studio3.0或者2.3 。使用新版Android Studio的往下看

 

如果你想要符合你編譯器默認的,就新建一個項目,對比一下,然而我在使用了它新建後默認的classpath3.6.1和gradle5.5後,出現了,NoClassDefFoundError: com/android/builder/Version(解決辦法:https://blog.csdn.net/qq_27454233/article/details/105123212,網上搜不到,可能需要所有配置都改一下,包括app下的build.gradle,改compileSdkVersion和buildToolsVersion,需要的小夥伴可以嘗試一下,因爲此項目依賴了大量的第三方和引入了好幾個module,所以這些改配置很容易世界爆炸,還是改個版本沒那麼高的把。有大佬知道的話這個錯誤是爲什麼,望留言告訴我下,萬分感謝。

 

可以把依賴的compile改成implementation,修改的好處,網上很多。

那麼我的版本:

項目下build.gradle的
buildscript{dependencies {classpath 'com.android.tools.build:gradle:3.0.1'}}
gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

出現

Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':classpath'.

在項目下的build.gradle兩個repositories添加 google(),假如module裏有classpath的,要把module的對應上,同樣添加google()

apply from: 'config/global.gradle'

buildscript {
    ext.kotlin_version = '1.2.30'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath "com.tencent.bugly:tinker-support:1.1.1"
        classpath 'com.meituan.android.walle:plugin:1.1.5'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        mavenCentral()
        jcenter()
        google()
        maven {
            url 'http://maven.aliyun.com/nexus/content/repositories/releases/'
        }
        maven {
            url "https://jitpack.io"
        }
        maven {
            url "https://dl.bintray.com/thelasterstar/maven/"
        }
        maven {
            url "https://maven.google.com"
        }
        maven {
            url "https://dl.google.com/dl/android/maven2/"
        }
        flatDir{
            dir 'libs'
        }
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

 

出現module Unable to resolve dependency for ':app@dev/compileClasspath'的話,你看看是不是用了devCompile,使用了dev的東西,你的module是沒有dev的,把dev去掉就行了。

比如說:

//    for leak memory
//    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
//    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
//    testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'

PS:升級Android Studio我也不想的啊,可是RN項目的安卓包,不升級就跑不起來,開始很多配置上的問題,用Android Studio編譯通過後更方便些,當然有更好的辦法,可以留言告訴我一下,感謝哦。

寫的很亂,不過主要是編譯失敗的問題,看對應的就行了,搞了一上午配置了,喜歡的話點個贊喲。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章