Skip to content

Commit

Permalink
update build
Browse files Browse the repository at this point in the history
  • Loading branch information
8enet committed Jan 11, 2018
1 parent 5cb0366 commit bbd38aa
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ cache:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/

script: ./gradlew clean assembleDebug
script: ./gradlew clean assembleRelease
4 changes: 0 additions & 4 deletions AdbLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,3 @@ android {
}
}
}

dependencies {

}
40 changes: 28 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import java.util.zip.ZipFile

apply plugin: 'com.android.application'

apply from: "../private/privateResource.gradle"

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
Expand All @@ -28,11 +30,21 @@ android {
exclude 'META-INF/NOTICE.txt'
}

signingConfigs {
release{
storeFile JEK_FILE_DECRYPTED
keyAlias project.myEnv.KEY_ALIAS
storePassword project.myEnv.STORE_PASSWORD
keyPassword project.myEnv.KEY_PASSWORD
}
}

buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}
Expand All @@ -54,28 +66,32 @@ dependencies {
implementation ('com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0@aar'){
transitive=true
}

releaseImplementation 'com.umeng.analytics:analytics:latest.integration'
}


task providedApiCompat <<{
println("------------- providedApiCompat ")
task providedApiCompat {

dependsOn(":apicompat:build")
doLast {

new ZipFile("${rootProject.project("apicompat").buildDir}/outputs/aar/apicompat-debug.aar").withCloseable {
println("------------- providedApiCompat ")

it.getInputStream(it.getEntry("classes.jar")).withStream{
def ins = it
def target = file("${project.projectDir}/deps/hidden.jar")
target.getParentFile().mkdirs()
target.withOutputStream {
it << ins
new ZipFile("${rootProject.project("apicompat").buildDir}/outputs/aar/apicompat-debug.aar").withCloseable {

it.getInputStream(it.getEntry("classes.jar")).withStream{
def ins = it
def target = file("${project.projectDir}/deps/hidden.jar")
target.getParentFile().mkdirs()
target.withOutputStream {
it << ins
}
}
}

}

}


providedApiCompat.execute()

preBuild.dependsOn(":apicompat:build",providedApiCompat)
10 changes: 5 additions & 5 deletions opsxpro/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path 'src/main/c/CMakeLists.txt'
}
}
// externalNativeBuild {
// cmake {
// path 'src/main/c/CMakeLists.txt'
// }
// }
}

dependencies {
Expand Down
9 changes: 9 additions & 0 deletions private/buildEnv.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
JKS_FILE=
JKS_PWD=
STORE_PASSWORD=
KEY_ALIAS=
KEY_PASSWORD=

P_FILE_SERVER=
P_SERVER_PWD=
P_SERVER_AUTH=
36 changes: 36 additions & 0 deletions private/env.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
project.extensions.create("myEnv",EnvProperties,rootProject.file("private/buildEnv.properties"))


class EnvProperties{
Properties properties = new Properties()

EnvProperties(File file){
loadProperty(file)
}

private loadProperty(File file){
if(file.exists()){
file.withInputStream {
ins -> properties.load(ins)
}
}

properties.each {
if(it.value ==null || it.value.toString().isEmpty()){
def sysEnv = System.getenv(it.key)
if(sysEnv != null && !sysEnv.toString().isEmpty()){
properties.put(it.key,sysEnv)
}

}
}
}

def propertyMissing(String name) {
def v=properties.getProperty(name)
if(v == null){
return null
}
v.integer?v.toInteger():v.toString()
}
}
Binary file added private/myapp.jks.enc
Binary file not shown.
141 changes: 141 additions & 0 deletions private/privateResource.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
apply from: "../private/env.gradle"

import javax.crypto.Cipher
import javax.crypto.spec.SecretKeySpec
import java.nio.file.Files
import java.security.MessageDigest

ext{
JEK_FILE_DECRYPTED = rootProject.file("private/myapp.jks")
}


static def checkEmpty(String... str) {
if (str == null) {
return true
}
for (String s : str) {
if (s == null || s.isEmpty()) {
return true
}
}
return false
}

task releaseSigningConfigs {

println("-----releaseSigningConfigs----")
def jksPwd = project.myEnv.JKS_PWD
if (checkEmpty(jksPwd,project.myEnv.JKS_FILE)) {
println("sign config error!!")
return
}

try {
def cipher = Cipher.getInstance("AES")
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(jksPwd.getBytes(), "AES"))

def bytes = cipher.doFinal(file(rootProject.file(project.myEnv.JKS_FILE)).bytes)

JEK_FILE_DECRYPTED.withOutputStream {
it.write(bytes)
}

} catch (Throwable throwable) {
throwable.printStackTrace()
}
}


task pushApkFile {

doLast {

println("-----pushApkFile----")

def server = project.myEnv.P_FILE_SERVER
def pwd = project.myEnv.P_SERVER_PWD
def auth = project.myEnv.P_SERVER_AUTH
if (checkEmpty(server, pwd, auth)) {
println("config error!!")
return
}
def sourceApk = project.file("build/outputs/apk/release/app-release.apk")

if (!sourceApk.exists()) {
println("release apk not found !")
return
}

def apk = project.file("appopsx-v${VERSION_NAME}-${new Date().format("yyyyMMddHHssmm")}.apk")

Files.copy(sourceApk.toPath(), apk.toPath())


apk.newInputStream().withStream {
MessageDigest digest = MessageDigest.getInstance("MD5")
byte[] buff = new byte[1024 * 256]
int l = -1
while ((l = it.read(buff, 0, buff.length)) != -1) {
digest.update(buff, 0, l)
}
def checksum = new BigInteger(1, digest.digest()).toString(16).padLeft(32, "0")
println("${apk} md5:" + checksum)
}

String CRLF = "\r\n";

HttpURLConnection connection = new URL(server).openConnection()
connection.setRequestMethod("POST")
connection.setDoInput(true)
connection.setDoOutput(true)
String boundary = "------------${Long.toHexString(System.nanoTime())}${Integer.toHexString(thisObject.hashCode())}"

connection.addRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary.substring(2))

def text = new StringBuilder(boundary).append(CRLF)
.append("Content-Disposition: form-data; name=\"pwd\"").append(CRLF)
.append("Content-Type: text/plain; charset=utf-8").append(CRLF)
.append(CRLF)
.append(pwd)
.append(CRLF)
.append(boundary)
.append(CRLF)
.append("Content-Disposition: form-data; name=\"file\"; filename=\"" + apk.getName() + "\"").append(CRLF)
.append("Content-Type: application/vnd.android.package-archive").append(CRLF)
.append("Content-Transfer-Encoding: binary").append(CRLF)
.append(CRLF).toString().bytes

def end = (CRLF + boundary + "--" + CRLF).toString().bytes

connection.addRequestProperty("Authorization", "Basic " + auth.bytes.encodeBase64())

connection.outputStream.write(text)
connection.outputStream.flush()
Files.copy(apk.toPath(), connection.outputStream)
connection.outputStream.flush()
connection.outputStream.write(end)
connection.outputStream.flush()

if (connection.responseCode == HttpURLConnection.HTTP_OK) {
println("server success response: " + connection.inputStream.newReader().text)
} else {
println("server ERROR response: " + connection.errorStream.newReader().text)
}
connection.disconnect()
}

}

task releaseResource{
doLast{
JEK_FILE_DECRYPTED.delete()
}
}

tasks.whenTaskAdded { task ->
println("$task.name")
if (task.name == "assembleRelease") {
task.finalizedBy(pushApkFile,releaseResource)
}
}

0 comments on commit bbd38aa

Please sign in to comment.