一、在https://www.androiddevtools.cn上下载Android SDK 二、下载完成后解压 三、双击SDK Manager.exe根据需要下载开发包
四、设置IDEA的SDKs 五、创建一个Android项目 六、创建一个虚拟机 七、下载一个gradle 官网下载太慢了,我从其他渠道下载的 https://pan.baidu.com/s/1bq4x31TueDr0g4_QJF_EbQ,下载完成后解压,配置系统环境变量
八、配置IDEA gradle、设置本地gradle位置和工作目录 九、设置阿里云中央仓库 具体设置项目下的build.gradle文件,这个是项目的全局gradle配置文件
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { mavenLocal() maven { url "http://maven.aliyun.com/nexus/content/groups/public/"} mavenCentral() jcenter() maven { url "https://repo.spring.io/snapshot" } maven { url "https://repo.spring.io/milestone" } maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' } //转换pdf使用 google() } dependencies { classpath 'com.android.tools.build:gradle:3.1.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } maven{ url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'} google() } } task clean(type: Delete) { delete rootProject.buildDir } dependencies { }十、整个项目的目录结构 十一、关键的几个文件 app文件夹下的gradle文件,项目构建的时候,会抱错,解析不出符号R,解决的办法是使用这句 implementation 'com.android.support:appcompat-v7:+' build.gradle
apply plugin: 'com.android.application' android { compileSdkVersion 29 defaultConfig { applicationId "com.example.administrator.myapplication" minSdkVersion 15 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) // implementation 'com.android.support:appcompat-v7:29.+' implementation 'com.android.support:appcompat-v7:+' implementation 'com.android.support.constraint:constraint-layout:2.0.1' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' }AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.administrator.myapplication"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> </manifest>MainActivity
package com.example.administrator.myapplication; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }十二、结果演示