内容纲要

在命令行下编译应用

[code]
./gradlew clean
./gradlew assembleRelease
[/code]

放入脚本中, compile.sh

[code]
#!/usr/bin/env bash
set -xeuo pipefail

./gradlew clean
./gradlew assembleRelease
[/code]

https://github.com/elye/demo_android_docker 下有一个 docker 下构建的工程模板, 使用例子

[code]
$ cd /mnt/src
$ git clone –depth=1 https://github.com/elye/demo_android_docker.git
$ cd demo_android_docker
[/code]

构建 docker 镜像

[code]
$ ls scripts
$ ./scripts/pack_sdk_docker_build.sh
[/code]

直接执行开始构建

[code]
$ ./scripts/pack_sdk_docker_run.sh ./scripts/compile.sh
[/code]

或者在当前目录下启动 docker 镜像, 目录会映射到 docker 容器下的 application

[code]
$ ./scripts/pack_sdk_docker_run.sh
[/code]

在 docker 容器下执行

[code]
$ cd /application
$ ./scripts/compile.sh
[/code]

启动编译时,总是自动下载 gradle-4.1-all.zip,非常缓慢, 用 wget 下载,然后存放在 gradle\wrapper\gradle-4.1-all.zip

修改 gradle-wrapper.properties 为

[code]
#Sun Nov 26 21:40:53 AEDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=gradle-4.1-all.zip

[/code]

修改 build.gradle, 添加 aliyun 的仓库

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

buildscript {
ext.kotlin_version = ‘1.2.0’
ext.gradle_tool_version = ‘3.0.1’
repositories {
maven {url ‘http://maven.aliyun.com/nexus/content/groups/public/’}
maven {url ‘http://maven.aliyun.com/nexus/content/repositories/google’ }
maven {url ‘http://maven.aliyun.com/nexus/content/repositories/jcenter’ }
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:$gradle_tool_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

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

allprojects {
repositories {
maven {url ‘http://maven.aliyun.com/nexus/content/groups/public/’}
maven {url ‘http://maven.aliyun.com/nexus/content/repositories/google’ }
maven {url ‘http://maven.aliyun.com/nexus/content/repositories/jcenter’ }
google()
jcenter()
}
}

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

[/code]

然后执行

[code]
./gradlew clean
./gradlew assembleRelease
[/code]

编译时出现错误

[code]
Could not resolve com.google.code.findbugs:jsr305:2.0.1.
[/code]

在相关项目的 build.gradle 下添加

[code]
android {
configurations.all {
resolutionStrategy.force ‘com.google.code.findbugs:jsr305:3.0.2’
}
}
[/code]

另外一个编译 android 应用的 docker 镜像

[code]
docker pull jangrewe/gitlab-ci-android
[/code]

[code]
docker run -it –rm -v "$PWD":/application jangrewe/gitlab-ci-android /bin/bash

./gradlew clean
./gradlew assembleRelease
[/code]

链接

发表评论

电子邮件地址不会被公开。 必填项已用*标注