zoukankan      html  css  js  c++  java
  • 基于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:+'
    }

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

     
     
     
     
     
  • 相关阅读:
    往下滚动,导航栏隐藏
    判断是模拟器还是真机
    根据颜色生成图片
    UITextfiled 设置输入前面空格
    iOS 滑动TableView控制导航栏隐藏与显示
    时间 多少分钟前
    时间戳转时间
    iOS 常用公共方法(一)
    找工作感悟
    java 内存泄露
  • 原文地址:https://www.cnblogs.com/JHblogs/p/8485072.html
Copyright © 2011-2022 走看看