基于androidstudio3.0的build文件配置问题

最近,在研究APP自动化相关的东西,在搭建环境的时候,遇到的坑以及最后解决的方法,不过目前很多东西了解得还不是很细,暂时先简单的记录一下
一、build配置文件

主要分为两种:

1、工程下的build配置文件;

2、模块目录的build配置文件;如下图:

1)工程下的build文件配置,主要包括以下内容:

1、repositories闭包
  该闭包中声明了jcenter()的配置,其中jcenter是一个代码托管仓库,上面托管了很多Android开源项目,在这里配置了jcenter后我们可以在项目中方便引用jcenter上的开源项目。
2、dependencies闭包
  该闭包使用classpath声明了一个Gradle插件,由于Gradle并不只是用来构建Android项目,因此此处引入相关插件来构建Android项目,其中'3.0.1'为该插件的版本号,可以根据最新的版本号来调整。
具体配置内容如下:
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
        //使用maven仓库。android有两个标准的library文件服务器,一个jcenter一个maven。两者毫无关系。
        //jcenter有的maven可能没有,反之亦然。
        //如果要使用jcenter的话就把mavenCentral()替换成jcenter()
        google()
        jcenter()
       // mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}


// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        //mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}


allprojects {
    repositories {
        google()
        jcenter()
        //mavenCentral()
        //maven { url "http://18.8.10.110:8081/nexus/content/repositories/releases/" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

 

 
2)模块目录下的build文件配置,主要包括以下内容:
1、 defaultConfig闭包
  
对项目的更多细节进行配置,其中applicationId指定了项目的包名,我们可以通过修改这个值来修改项目的包名。
2、 buildTypes闭包
  
这个闭包主要指定生成安装文件的主要配置,一般包含两个子闭包,一个是debug闭包,用于指定生成测试版安装文件的配置,可以忽略不写;另一个是release闭包,用于指定生成正式版安装文件的配置。
3、dependencies闭包
  该闭包定义了项目的依赖关系,一般项目都有三种依赖方式:本地依赖、库依赖和远程依赖。本地依赖可以对本地的jar包或目录添加依赖关系,库依赖可以对项目中的库模块添加依赖关系,远程依赖可以对jcener库上的开源项目添加依赖关系。
 
具体配置内容如下:
//声明是Android程序
apply plugin: 'com.android.application'

android {
    //编译sdk的版本,也就是API Level,例如API-23、API-24、API-25等等
    compileSdkVersion 26
    //build tools的版本,其中包括了打包工具aapt、dx等等。
    //这个工具的目录位于你的sdk目录/build-tools/下
    buildToolsVersion '26.0.2'
    defaultConfig {
        //应用包名
        applicationId "com.cxq.myapplication"
        //最小sdk版本,如果设备小于这个版本或者大于maxSdkVersion(一般不用)将无法安装这个应用
        minSdkVersion 26
        //目标sdk版本,如果设备等于这个版本那么android平台就不进行兼容性检查,运行效率会高一点
        targetSdkVersion 26
        //版本更新了几次,第一版应用是1,以后每更新一次加1
        versionCode 1
        //版本信息,这个会显示给用户,就是用户看到的版本号
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {//release版本的配置
            minifyEnabled false  //是否进行混淆
            //release的Proguard默认为Module下的proguard-rules.pro文件.
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            matchingFallbacks = ['release', 'debug']
        }
    }

}

//一些依赖的框架
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    androidTestImplementation 'com.android.support.test:rules:1.0.1'
    implementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
    //implementation files('libs/uiautomator.jar')
    //implementation 'com.gionee.autotests.common:common-lib:1.0.7'
    //implementation 'com.gionee.android.autotests.common:android-common:+'
}

还有一些其他的设置问题,后续再做更新;

 
 
 
 
 

转载于:https://www.cnblogs.com/JHblogs/p/8485072.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值