The correct way to open old projects in Android Studio

The correct way to open old projects in Android Studio

Andriod Studio has developed relatively quickly, and now 3.6.3 is generally used com.android.tools.build:gradle. If you open some 2.x.xversions, various errors will be reported. For example, the google() method cannot be recognized, for example, it can be compiled but cannot be installed automatically. You may ask why open some old projects? Most of the SDKs on Github are like 2.x.xthis, even the SDKs produced by some major manufacturers. If you want to use the SDK to view demos, you must download and open the old project. There is no way around it. Android Studio is not as powerful as Office software and can open any older version of Word files. There 2.x.xwill be some problems in the projects opened by Android Studio. Let’s take it as a matter and record it carefully. Don't worry, if you don't handle the demo that you expect to spend 20 minutes to get familiar with, it may take 4 hours to solve.


This is the build.gradle of a typical old project

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

gradle/wrapper/gradle-wrapper.properties

Phenomenon: When Android Studio opens an old project and clicks "run", it will only compile and not automatically install. The error reported in the title may be a configuration problem. I checked online that it was com.android.tools.build:gradlecaused by the version being too low. Old projects on the Internet can usually be 2.x.x
replaced .3.6.3

buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' } // 添加这一行解决下载不了3.6.3的问题 这个不能直接使用google()低版本的gradle不认这个语法
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3' //修改成高版本以解决低版本的问题
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' } // 添加这一行解决下载不了android suport的问题
    }
}

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

Guess you like

Origin blog.csdn.net/kangear/article/details/117879379