yetang307

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
编译配置文件build.gradle 
(1)项目级别
    buildscript{
        repositories{
// 以下四行添加阿里云的仓库地址,方便国内开发者下载相关插件
            maven{url'https://maven.aliyun.com/repository/jcenter'}
            maven{url'https://maven.aliyun.com/repository/google'}
            maven{url'https://maven.aliyun.com/repository/gradle-plugin'}
            maven{url'https://maven.aliyun.com/repository/public'}
            google()
            jcenter()
        }
        dependencies{
// 配置gradle插件版本,下面的版本号就是Android Studio的版本号
            classpath'com.android.tools.build:gradle:4.1.0'
        }
    }

(2)模块级别

android {
// 指定编译用的SDK版本号。比如30表示使用Android 11.0编译
        compileSdkVersion 30
// 指定编译工具的版本号。这里的头两位数字必须与compileSdkVersion保持一致,具体的版本号可
        在sdk安装目录的“sdk\build-tools”下找到
        buildToolsVersion "30.0.3"
        defaultConfig {
// 指定该模块的应用编号,也就是App的包名
            applicationId "com.example.chapter02"
// 指定App适合运行的最小SDK版本号。比如19表示至少要在Android 4.4上运行
            minSdkVersion 19
// 指定目标设备的SDK版本号。表示App最希望在哪个版本的Android上运行
            targetSdkVersion 30
// 指定App的应用版本号
            versionCode 1
// 指定App的应用版本名称
            versionName "1.0"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-androidoptimize.txt'), 'proguard-rules.pro'
            }
        }
    }
    // 指定App编译的依赖信息
    dependencies {
// 指定引用jar包的路径
        implementation fileTree(dir: 'libs', include: ['*.jar'])
// 指定编译Android的高版本支持库。如AppCompatActivity必须指定编译appcompat库
//appcompat库各版本见
        https://mvnrepository.com/artifact/androidx.appcompat/appcompat
        implementation 'androidx.appcompat:appcompat:1.2.0'
// 指定单元测试编译用的junit版本号
        testImplementation 'junit:junit:4.13'
        androidTestImplementation 'androidx.test.ext:junit:1.1.2'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    }
 运行配置文件AndroidManifest.xml 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.chapter02">
    <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=".Main2Activity"></activity>
        <!-- activity节点指定了该App拥有的活动页面信息,其中拥有
        android.intent.action.MAIN的activity说明它是入口页面 -->
        <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>

 

posted on 2023-02-22 20:18  椰糖  阅读(10)  评论(0)    收藏  举报