Skip to content

Commit

Permalink
迁移到AndroidX,同时,demo增加release打包和混淆功能。
Browse files Browse the repository at this point in the history
  • Loading branch information
yuruiyin committed Jun 10, 2019
1 parent 5b66acc commit 6198e9c
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 60 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,29 @@ dependencies {

</android.support.design.widget.AppBarLayout>
```

### 混淆
若使用support库,则需要保证support库中的代码不被混淆,请在proguard-rules.pro中添加如下配置:
```proguard
# 保留support下的所有类及内部类
-keep class android.support.**{*;}
-dontwarn android.support.v4.**
# 保留继承support库的类
-keep public class * extends android.support.v4.**
-keep public class * extends android.support.v7.**
-keep public class * extends android.support.annotation.**
```

若已迁移到androidx,则需要添加如下配置:
```proguard
-keep class com.google.android.material.** {*;}
-keep class androidx.** {*;}
-keep public class * extends androidx.**
-keep interface androidx.** {*;}
-dontwarn com.google.android.material.**
-dontnote com.google.android.material.**
-dontwarn androidx.**
```

## 参考
https://blog.csdn.net/vite_s/article/details/78901767
18 changes: 9 additions & 9 deletions appbarlayoutbehavior/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ apply plugin: 'com.github.dcendents.android-maven'
group='com.github.yuruiyin'

android {
compileSdkVersion 27
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
minSdkVersion 15
targetSdkVersion 27
buildToolsVersion '27.0.3'
minSdkVersion rootProject.ext.minSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

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

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.yuruiyin.appbarlayoutbehavior;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.yuruiyin.appbarlayoutbehavior;

import android.content.Context;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import com.google.android.material.appbar.AppBarLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
Expand Down
22 changes: 11 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.4.1'

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

Expand Down Expand Up @@ -38,14 +38,14 @@ ext {
androidSupportVersion = "28.0.0"
}

subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion androidSupportVersion
}
}
}
}
//subprojects {
// project.configurations.all {
// resolutionStrategy.eachDependency { details ->
// if (details.requested.group == 'com.android.support'
// && !details.requested.name.contains('multidex') ) {
// details.useVersion androidSupportVersion
// }
// }
// }
//}

2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# 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.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jul 13 17:23:18 CST 2018
#Mon Jun 10 23:58:55 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Binary file added sample/android.keystore
Binary file not shown.
46 changes: 37 additions & 9 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,40 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 3
versionName "1.0.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
debug {
storeFile file('android.keystore')
storePassword "123456"
keyAlias "AppbarLayoutBehavior"
keyPassword "123456"
v1SigningEnabled true
v2SigningEnabled true
}

release {
storeFile file('android.keystore')
storePassword "123456"
keyAlias "AppbarLayoutBehavior"
keyPassword "123456"
v1SigningEnabled true
v2SigningEnabled true
}
}

buildTypes {
debug {
signingConfig signingConfigs.debug
ext.enableCrashlytics = false
}
release {
minifyEnabled false
shrinkResources true
zipAlignEnabled true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}

Expand All @@ -26,17 +54,17 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:$androidSupportVersion"
implementation "com.android.support:design:$androidSupportVersion"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

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

implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'

implementation project(':appbarlayoutbehavior')

Expand Down
17 changes: 17 additions & 0 deletions sample/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,20 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

# 保留support下的所有类及内部类
-keep class android.support.**{*;}
-dontwarn android.support.v4.**
# 保留继承support库的类
-keep public class * extends android.support.v4.**
-keep public class * extends android.support.v7.**
-keep public class * extends android.support.annotation.**

# 若使用androidx
-keep class com.google.android.material.** {*;}
-keep class androidx.** {*;}
-keep public class * extends androidx.**
-keep interface androidx.** {*;}
-dontwarn com.google.android.material.**
-dontnote com.google.android.material.**
-dontwarn androidx.**
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.yuruiyin.sample;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
10 changes: 5 additions & 5 deletions sample/src/main/java/com/yuruiyin/sample/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.yuruiyin.sample;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;

import com.yuruiyin.sample.adapter.CustomIndicatorAdapter;

Expand Down
10 changes: 5 additions & 5 deletions sample/src/main/java/com/yuruiyin/sample/MyListFragment.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.yuruiyin.sample;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.content.Context;
import android.graphics.Color;
import android.support.v4.view.ViewPager;
import androidx.viewpager.widget.ViewPager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.yuruiyin.sample.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.yuruiyin.sample.R;
Expand Down
14 changes: 7 additions & 7 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>

<android.support.design.widget.AppBarLayout
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -16,7 +16,7 @@
app:layout_behavior="com.yuruiyin.appbarlayoutbehavior.AppBarLayoutBehavior"
>

<android.support.design.widget.CollapsingToolbarLayout
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
Expand All @@ -32,7 +32,7 @@
app:layout_collapseMode="parallax"
/>

</android.support.design.widget.CollapsingToolbarLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>

<!-- 需要悬停的布局:玩家评价title -->
<net.lucode.hackware.magicindicator.MagicIndicator
Expand All @@ -50,14 +50,14 @@
android:background="#aaaaaa"
/>

</android.support.design.widget.AppBarLayout>
</com.google.android.material.appbar.AppBarLayout>

<android.support.v4.view.ViewPager
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>

</android.support.design.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/fragment_list.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
<androidx.recyclerview.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
Expand Down

0 comments on commit 6198e9c

Please sign in to comment.