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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM