1.新建Android项目
1.1修改Android项目中gradle版本
点击Android studio左上角的File菜单,选中Project structure,如下图所示:
将Android Gradle Plugin Version的版本修改为3.5.4,并且将Gradle Version的版本修改为6.5,如下图所示:
1.2修改Android项目中gradle版本(项目下的)
在项目下的build.gradle中添加Replugin的仓库地址,代码如下所示:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
//添加kotlin的支持
ext.kotlin_version = "1.6.10"
repositories {
google()
mavenCentral()
//replugin地址
maven {url "http://maven.geelib.360.cn/nexus/repository/replugin/"}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
//replugin插件插件
classpath 'com.qihoo360.replugin:replugin-plugin-gradle:3.0.0'
//replugin宿主插件
classpath "com.qihoo360.replugin:replugin-host-gradle:3.0.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
//replugin的地址
maven {url "http://maven.geelib.360.cn/nexus/repository/replugin/"}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Android studio中右上角会提示sync,点击更新一下。
1.3修改App下的gradle版本
在Android闭包下添加:
apply plugin: 'replugin-host-gradle'
在dependencies闭包中添加replugin的依赖
implementation "com.qihoo360.replugin:replugin-host-lib:3.0.0"
所有代码如下所示:
plugins {
id 'com.android.application'
id 'kotlin-android-extensions'
id 'kotlin-android'
}
android {
compileSdkVersion 28
buildToolsVersion "28.0.0"
defaultConfig {
applicationId "com.hong.replugin360"
minSdkVersion 16
targetSdkVersion 28
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
//必须在Android的闭包下
apply plugin: 'replugin-host-gradle'
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$