Android Studio 项目文件及目录详解

manifest目录

AndroidManifest.xml

<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>

java目录

com.example.xxx

xxxx.java:活动文件

res目录

drawable:存放图片

layout:存放布局文件

mipmap:存放图标

values:存放字符串、样式、颜色

strings.xml:存放字符串

  • java代码调用:R.string.name
  • XML调用:@string/name

Gradle Scripts

build.gradle(Project:xxxx)

buildscript {
    repositories {
        google()
        jcenter() 	//jcenter引用
    }
    dependencies {
    	//声明Gradle编译插件
        classpath 'com.android.tools.build:gradle:3.6.3'
    }
}
allprojects {
    repositories {
        google()
        jcenter() 
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(Module:app)

//表示这是一个应用程序模块
apply plugin: 'com.android.application'
//com.android.alibrary:表示库模块

android {
	//编译版本
    compileSdkVersion 29	
    //项目构建工具版本
    buildToolsVersion "29.0.3"
   	
   	//项目细节配置
    defaultConfig {
    	//指定项目包名
        applicationId "com.example.test"
        //最低兼容版本
        minSdkVersion 16
        //经过测试的版本
        targetSdkVersion 29
        //指定项目版本号
        versionCode 1
        //指定项目版本名
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    
    //生成安装文件配置
    buildTypes {
    	//生产正式版本文件配置
        release {
        	//是否代码混淆
            minifyEnabled false
            //指定混淆规则文件
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

//依赖关系配置
dependencies {
	//本地依赖(libs目录下的所有后缀为jar文件)
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

上一篇:[android]com.android.support:appcompat-v7:XXX 包导入无法Build


下一篇:迁移到androidx后错误膨胀类androidx.constraintlayout.ConstraintLayout