记录一下导入《从零基础到APP上线》工程遇到的问题。
例程:《junior》。
原例程平台:Android Studio 2.2.3 ,SDK为Android7.1.1(API25)和25.0.1版本的编译工具。
现平台:Android Studio 3.5.2。
一,直接导入工程遇到一下问题.
ERROR: Plugin with id 'com.android.application' not found.
旧工程只有Module的build.gradle、没有Project的build.gradle;
网上给出解决方法;
1、找一个可以正常编译的项目或新建一个项目,把Project中的build.gradle中的代码复制一下,如下图;
2、粘贴到这个报错项目的build.gradle中,放在最下面即可,下面代码;
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//testimplementation 'junit:junit:4.12'//单元测试相关可以屏蔽
//compile 'com.android.support:appcompat-v7:28.0.3'
implementation 'com.android.support:appcompat-v7:28.0.0'//查找当前电脑中存在的库版本号
}
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
3,编译工程,出现一下错误。
4,根据提示,双击“Install Build Tools 27.0.3 and sync project”,安装 “Build Tools 27.0.3”。
5,安装之后编译如下。
6,根据提示进行关键词替换。
提示“Configuration 'compile' is obsolete and has been replaced with 'implementation'.”
替换关键词之后。还剩一个问题。
The specified Android SDK Build Tools version (25.0.2) is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.0.
看起来是Gradle Plugin 3.1.0版本高了,得version (27.0.3)以上才支持。
7,在文件中屏蔽掉“BuildToolsversion 25.0.2”,再编译就没问题了,应该是用了系统中别的版本的编译工具。
8,我的电脑配置成功的文件。注意:在网页直接复制到Android studio好像有问题。
apply plugin: 'com.android.application'
android {
compileSdkVersion 28 //SDK 版本
buildToolsVersion "28.0.3" //buildTools 版本
defaultConfig {
applicationId "com.example.junior"//
minSdkVersion 22 //最小支持SDK版本
targetSdkVersion 28 //目标安装的SDK版本
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//testimplementation 'junit:junit:4.12' //单元测试相关可以屏蔽
implementation 'com.android.support:appcompat-v7:28.0.0'//当前电脑中存在的库版本号
}
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}