需要安装三个东西。
JDK
Android SDK
Android Studio
这三种下载最新版本的。
下载完之后,查看android studio的sdk路径。如果不对,自行配置。然后运行studio,运行过程中会有错误,将错误黏贴至搜索引擎,按照搜索结果解决即可。
需要关注的几个路径以及文件
android sdk的位置
gradle的位置
gradle文件
项目的gradle版本以及gradle插件版本以及dependency的写法 这些都有版本冲突
gradle插件版本在build.gradle中
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
gradle路径在下面注意到网上查看对应关系
项目中的build.gradle也很重要
plugins {
id 'com.android.application'
}
android {
compileSdk 30
defaultConfig {
applicationId "com.example.contentprovider"
minSdk 21
targetSdk 30
versionCode 1
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
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}