-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
220 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,3 @@ android { | |
} | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |