Skip to content

Commit 6198e9c

Browse files
committed
迁移到AndroidX,同时,demo增加release打包和混淆功能。
1 parent 5b66acc commit 6198e9c

File tree

18 files changed

+131
-60
lines changed

18 files changed

+131
-60
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,29 @@ dependencies {
3939

4040
</android.support.design.widget.AppBarLayout>
4141
```
42+
43+
### 混淆
44+
若使用support库,则需要保证support库中的代码不被混淆,请在proguard-rules.pro中添加如下配置:
45+
```proguard
46+
# 保留support下的所有类及内部类
47+
-keep class android.support.**{*;}
48+
-dontwarn android.support.v4.**
49+
# 保留继承support库的类
50+
-keep public class * extends android.support.v4.**
51+
-keep public class * extends android.support.v7.**
52+
-keep public class * extends android.support.annotation.**
53+
```
54+
55+
若已迁移到androidx,则需要添加如下配置:
56+
```proguard
57+
-keep class com.google.android.material.** {*;}
58+
-keep class androidx.** {*;}
59+
-keep public class * extends androidx.**
60+
-keep interface androidx.** {*;}
61+
-dontwarn com.google.android.material.**
62+
-dontnote com.google.android.material.**
63+
-dontwarn androidx.**
64+
```
65+
4266
## 参考
4367
https://blog.csdn.net/vite_s/article/details/78901767

appbarlayoutbehavior/build.gradle

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ apply plugin: 'com.github.dcendents.android-maven'
44
group='com.github.yuruiyin'
55

66
android {
7-
compileSdkVersion 27
7+
compileSdkVersion rootProject.ext.compileSdkVersion
88

99
defaultConfig {
10-
minSdkVersion 15
11-
targetSdkVersion 27
12-
buildToolsVersion '27.0.3'
10+
minSdkVersion rootProject.ext.minSdkVersion
11+
buildToolsVersion rootProject.ext.buildToolsVersion
12+
targetSdkVersion rootProject.ext.targetSdkVersion
1313
versionCode 1
1414
versionName "1.0"
1515

16-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1717

1818
}
1919

@@ -29,9 +29,9 @@ android {
2929
dependencies {
3030
implementation fileTree(dir: 'libs', include: ['*.jar'])
3131

32-
implementation 'com.android.support:appcompat-v7:27.1.1'
33-
implementation 'com.android.support:design:27.1.1'
32+
implementation 'androidx.appcompat:appcompat:1.0.2'
33+
implementation 'com.google.android.material:material:1.0.0'
3434
testImplementation 'junit:junit:4.12'
35-
androidTestImplementation 'com.android.support.test:runner:1.0.2'
36-
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
35+
androidTestImplementation 'androidx.test:runner:1.2.0'
36+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
3737
}

appbarlayoutbehavior/src/androidTest/java/com/yuruiyin/appbarlayoutbehavior/ExampleInstrumentedTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.yuruiyin.appbarlayoutbehavior;
22

33
import android.content.Context;
4-
import android.support.test.InstrumentationRegistry;
5-
import android.support.test.runner.AndroidJUnit4;
4+
import androidx.test.InstrumentationRegistry;
5+
import androidx.test.runner.AndroidJUnit4;
66

77
import org.junit.Test;
88
import org.junit.runner.RunWith;

appbarlayoutbehavior/src/main/java/com/yuruiyin/appbarlayoutbehavior/AppBarLayoutBehavior.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.yuruiyin.appbarlayoutbehavior;
22

33
import android.content.Context;
4-
import android.support.design.widget.AppBarLayout;
5-
import android.support.design.widget.CoordinatorLayout;
4+
import com.google.android.material.appbar.AppBarLayout;
5+
import androidx.coordinatorlayout.widget.CoordinatorLayout;
66
import android.util.AttributeSet;
77
import android.view.MotionEvent;
88
import android.view.View;

build.gradle

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.1.4'
10+
classpath 'com.android.tools.build:gradle:3.4.1'
1111

1212
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
1313

@@ -38,14 +38,14 @@ ext {
3838
androidSupportVersion = "28.0.0"
3939
}
4040

41-
subprojects {
42-
project.configurations.all {
43-
resolutionStrategy.eachDependency { details ->
44-
if (details.requested.group == 'com.android.support'
45-
&& !details.requested.name.contains('multidex') ) {
46-
details.useVersion androidSupportVersion
47-
}
48-
}
49-
}
50-
}
41+
//subprojects {
42+
// project.configurations.all {
43+
// resolutionStrategy.eachDependency { details ->
44+
// if (details.requested.group == 'com.android.support'
45+
// && !details.requested.name.contains('multidex') ) {
46+
// details.useVersion androidSupportVersion
47+
// }
48+
// }
49+
// }
50+
//}
5151

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# http://www.gradle.org/docs/current/userguide/build_environment.html
77
# Specifies the JVM arguments used for the daemon process.
88
# The setting is particularly useful for tweaking memory settings.
9+
android.enableJetifier=true
10+
android.useAndroidX=true
911
org.gradle.jvmargs=-Xmx1536m
1012
# When configured, Gradle will run in incubating parallel mode.
1113
# This option should only be used with decoupled projects. More details, visit
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Fri Jul 13 17:23:18 CST 2018
1+
#Mon Jun 10 23:58:55 CST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

sample/android.keystore

2.18 KB
Binary file not shown.

sample/build.gradle

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,40 @@ android {
99
targetSdkVersion rootProject.ext.targetSdkVersion
1010
versionCode 3
1111
versionName "1.0.2"
12-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
}
14+
15+
signingConfigs {
16+
debug {
17+
storeFile file('android.keystore')
18+
storePassword "123456"
19+
keyAlias "AppbarLayoutBehavior"
20+
keyPassword "123456"
21+
v1SigningEnabled true
22+
v2SigningEnabled true
23+
}
24+
25+
release {
26+
storeFile file('android.keystore')
27+
storePassword "123456"
28+
keyAlias "AppbarLayoutBehavior"
29+
keyPassword "123456"
30+
v1SigningEnabled true
31+
v2SigningEnabled true
32+
}
33+
}
34+
1435
buildTypes {
36+
debug {
37+
signingConfig signingConfigs.debug
38+
ext.enableCrashlytics = false
39+
}
1540
release {
16-
minifyEnabled false
41+
shrinkResources true
42+
zipAlignEnabled true
43+
minifyEnabled true
1744
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
45+
signingConfig signingConfigs.release
1846
}
1947
}
2048

@@ -26,17 +54,17 @@ android {
2654

2755
dependencies {
2856
implementation fileTree(dir: 'libs', include: ['*.jar'])
29-
implementation "com.android.support:appcompat-v7:$androidSupportVersion"
30-
implementation "com.android.support:design:$androidSupportVersion"
31-
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
57+
implementation 'androidx.appcompat:appcompat:1.0.2'
58+
implementation 'com.google.android.material:material:1.0.0'
59+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
3260
testImplementation 'junit:junit:4.12'
33-
androidTestImplementation 'com.android.support.test:runner:1.0.2'
34-
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
61+
androidTestImplementation 'androidx.test:runner:1.2.0'
62+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
3563

3664
implementation 'com.github.hackware1993:MagicIndicator:1.5.0'
3765

38-
implementation 'com.jakewharton:butterknife:8.8.1'
39-
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
66+
implementation 'com.jakewharton:butterknife:10.1.0'
67+
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
4068

4169
implementation project(':appbarlayoutbehavior')
4270

sample/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,20 @@
1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
2121
#-renamesourcefileattribute SourceFile
22+
23+
# 保留support下的所有类及内部类
24+
-keep class android.support.**{*;}
25+
-dontwarn android.support.v4.**
26+
# 保留继承support库的类
27+
-keep public class * extends android.support.v4.**
28+
-keep public class * extends android.support.v7.**
29+
-keep public class * extends android.support.annotation.**
30+
31+
# 若使用androidx
32+
-keep class com.google.android.material.** {*;}
33+
-keep class androidx.** {*;}
34+
-keep public class * extends androidx.**
35+
-keep interface androidx.** {*;}
36+
-dontwarn com.google.android.material.**
37+
-dontnote com.google.android.material.**
38+
-dontwarn androidx.**

0 commit comments

Comments
 (0)