Skip to content

Commit

Permalink
添加jks签名证书
Browse files Browse the repository at this point in the history
添加打正式包版本名 版本号关联git
添加基础混淆规则
  • Loading branch information
Mr-zhao-dy committed Aug 16, 2017
1 parent 1fb44e2 commit 34997e8
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added app/app-channel_default-release.apk
Binary file not shown.
124 changes: 122 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
Expand All @@ -12,21 +13,140 @@ android {
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dexOptions {
preDexLibraries = false
}

lintOptions {
abortOnError false
}
signingConfigs {
release {
try {
storeFile file(KEYSTORE_FILE)
storePassword KEYSTORE_PASSWORD
keyAlias KEYSTORE_ALIAS
keyPassword KEY_PASSWORD
}
catch (ignored) {
if (System.getenv("KEYSTORE_FILE") != null) {
storeFile = file(System.getenv("KEYSTORE_FILE"))
storePassword = System.getenv("KEYSTORE_PWD")
keyAlias = System.getenv("KEYSTORE_ALIAS")
keyPassword = System.getenv("KEYSTORE_ALIAS_PWD")
} else {
throw new InvalidUserDataException("You should define KEYSTORE_PASSWORD and KEY_PASSWORD in gradle.properties.")
}
}
}
}

buildTypes {
release {
minifyEnabled false
signingConfig signingConfigs.release
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
if (variant.buildType.name == 'release') {
variant.mergedFlavor.versionName = VersionName()
variant.mergedFlavor.versionCode = getGitVersionCode()
renameArtifact(variant)
}

}
}
}

productFlavors {

"360" {
applicationId "com.hcy.tomeetu"
}

huawei {
applicationId "com.hcy.tomeetu"
}

}
}

def renameArtifact(variant) {

variant.outputs.each { output ->
output.outputFile = new File(
(String) output.outputFile.parent,
(String) "${variant.productFlavors[0].name}-${variant.buildType.name}-code-${variant.versionCode}-(v${variant.versionName})-${releaseTime()}.apk".toLowerCase())
}
}

def releaseTime() {
return new Date().format("yyyyMMdd-HHmmss")
}


def getGitVersionCode() {

def cmd = 'git rev-list HEAD --count'

int gitVersion = cmd.execute().text.trim().toInteger()

println("the git version is : " + gitVersion)

return gitVersion

}
//使用git的Tag来自动定制Version
def VersionName() {
def cmd = 'git tag'
def tags = cmd.execute().text.readLines()
/* if (tags.size() >= 1) {
def version_last = tags.last().trim() //newest
cmd = 'git rev-list ' + version_last + '.. --count'
if (tags.size() >= 2) {
tags.remove(tags.last())
def version_last_2 = tags.last().trim() //newest
cmd = 'git rev-list ' + version_last_2 + '..' + version_last + ' --count'
}
} else {
cmd = 'git rev-list --count'
}*/
cmd = 'git rev-list --all --count'
def code = cmd.execute().text.trim().toInteger()

def versionName = tags.last().trim().replaceAll("[a-zA-Z]", "") + "-build" + code
logger.quiet(cmd + " >>>> versionName = " + versionName)
println("the git versionName is : " + versionName)
return versionName
}

def getGitCommitDescription() {

// def cmd = "git rev-parse --short HEAD"

def cmd = "git log -1 --pretty=format:%cd --date=iso"

def proc = cmd.execute()

String cmdResult = proc.text.trim()

String[] resultArray = cmdResult.replaceAll(":", "-").split()

String apkName = (resultArray[0] + "-" + resultArray[1]).replaceAll("-", "_")

println("the apkName is : " + apkName)

return apkName

}


dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
Expand Down
81 changes: 81 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,84 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
##################below is for common android
-keep public class **.R$* { public static final int *; }
-keep public class * extends android.app.Activity
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.view.View
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep class * implements android.os.Parcelable {public static final android.os.Parcelable$Creator *; }
# 保留自定义控件不能被混淆
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(***);
*** get* ();
}
# 保留Parcelable序列化的类不能被混淆
-keep class * implements android.os.Parcelable{
public static final android.os.Parcelable$Creator *;
}
# 保留Serializable 序列化的类不被混淆
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
!static !transient <fields>;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}

# 对R文件下的所有类及其方法,都不能被混淆
-keep class .R
-keepclassmembers class **.R$* {
*;
}
# 对于带有回调函数onXXEvent的,不能混淆
-keepclassmembers class * {
void *(**On*Event);
}
-keepclassmembers class * {
void *(**Callback);
}

#gson
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default_no_login, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

##---------------End: proguard configuration for Gson ----------


##---------------Begin: proguard configuration for RxJava ----------
-dontwarn sun.misc.**

-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}

-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
rx.internal.util.atomic.LinkedQueueNode producerNode;
}

-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
##---------------End: proguard configuration for RxJava ----------
5 changes: 2 additions & 3 deletions app/src/main/res/layout/activity_test.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.hcy.tomeetu.TestActivity">

</android.support.constraint.ConstraintLayout>
</LinearLayout>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.1.4'
ext.kotlin_version = '1.1.3'
repositories {
jcenter()
}
Expand Down
24 changes: 15 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

## Project-wide Gradle settings.
#
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m

# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Wed Aug 16 09:16:26 CST 2017
systemProp.http.proxyHost=127.0.0.1
org.gradle.jvmargs=-Xmx1536m
systemProp.http.proxyPort=8087
KEY_PASSWORD=123456
KEYSTORE_ALIAS=mymeet
KEYSTORE_PASSWORD=123456
kotlin.incremental=true
KEYSTORE_FILE=../jks/mymeet.jks
Binary file added jks/mymeet.jks
Binary file not shown.

0 comments on commit 34997e8

Please sign in to comment.