SDKHotfix(SDK ÈÈÐÞ¸´¹¤¾ß°ü)ÊÇÒ»¿îÈà SDK ¿ª·¢ÕßÄÜ¿ìËÙ¸³Óè SDK ÈÈÐÞ¸´µÄÄÜÁ¦.
SDKHotfix(SDK ÈÈÐÞ¸´¹¤¾ß°ü)Ìصã
5 ·ÖÖÓ¼´¿ÉÈÃÄãµÄ SDK ÓµÓÐÈÈÐÞ¸´µÄÄÜÁ¦
½ÚÊ¡²È¿ÓºÍ¿ª·¢³É±¾
hook and create Gradle Task
Kotlin + groovy
ÈÈÐÞ¸´
·Ç¶Ô³Æ¼ÓÃÜ+¶Ô³Æ¼ÓÃÜ
À©Õ¹ÃÀÍÅ Robust ¿ªÔ´¿â£¬Ê¹Æä¾ßÓÐÆäËûÈȸü¿â²»¾ß±¸µÄ²¹¶¡»Ø¹ö¹¦ÄÜ
Êý¾ÝºÍ¼à¿Ø˼ά
Óŵã
ÎÞ¼æÈÝÎÊÌâ
ʵʱÉúЧ
ÐÞ¸´³É¹¦Âʸߴï99.9%
ÔÚÓû§¹æģǧÍò¼¶±ðµÄappÖÐÑéÖ¤¹ý£¬¿ÉÐÅÀµ
Ö§³Ö²¹¶¡Òì³£×Ô¶¯Ê§Ð§£¬²»ÓÃÔÙµ£ÐIJ¹¶¡Ôì³ÉcrashÀ²~
´ý¸Ä½ø
ÔÚ±àÒë½×¶Î²å¼þÇÖÈëÁ˲úÆ·´úÂ룬¶ÔÔËÐÐЧÂÊ¡¢·½·¨Êý¡¢°üÌå»ý»¹ÊDzúÉúÁËһЩ¸±×÷Óᣣ¨¿ÉÖ¸¶¨Ä³Ð©classÎÞÐè²åÈë·½·¨£¬¼õÉÙ²å×®Êý£©
soºÍ×ÊÔ´µÄÌ滻ĿǰÔÝδʵÏÖ
¶ÔÓÚÖ»ÓÐ×ֶηÃÎʵĺ¯ÊýÎÞ·¨Ö±½ÓÐÞ¸´£¬¿Éͨ¹ýµ÷Óô¦¼ä½ÓÐÞ¸´
ÉÏ´«GradleTaskÉÐδÔÚMAC»·¾³Ï²âÊÔ
ÉÏ´«µÄ²¹¶¡Ö§³Ö°´°üÃû´æµµ
ÒªÉÌÓõÄС»ï°éҪעÒ⣬½¨Òé»»³É×Ô¼ºµÄºó¶Ë½Ó¿Ú»ò×Ô¼ºÐø·ÑÒ»¸öbmobÓ¦Óã¬ÒòΪbmobÔƺ¯Êý·þÎñ³¬¹ý40ÌìÐèÒªÊÕ·Ñ£¬ËùÒÔ±¾ÏîÄ¿ÐèÒª¶¨ÆÚ¸üÐÂÓ¦ÓÃÃØÔ¿¡£
ʹÓ÷½·¨
1. Ìí¼ÓÅäÖúͿª¹Ø
1.1 ÔÚÏîÄ¿gradle.propertiesÖÐÌí¼Ó¿ª¹ØºÍÅäÖÃ
# ½ÓÈëµÚÒ»²½£ºÌí¼ÓÅäÖúͿª¹Ø
# Applicationģʽ£¬RobustÐèÒªÊÇApplication²ÅÄܲåÈë´úÂëºÍ´ò²¹¶¡
isAppModule=false
# ApplicationģʽÏ¿ªÆôÕâ¸ö¾Í¿ÉÒÔ´ò²¹¶¡
isPatchModule=false
# ÄãµÄÒµÎñsdkµÄ°üÃû
sdkPackageName=com.feelschaotic.samplesdk
# ÊÇ·ñ¿ªÆô»ìÏý£¬Ò»°ãÇé¿öÏÂsdkĬÈϲ»»ìÏý
isProguard=false
# ÒµÎñsdk°æ±¾ºÅ£¬Çë±£³ÖÈý룬ÇÒÎÞºó׺£¬ÇÒÔÚ´ò°üÇ°¾ÍҪȷ¶¨ºÃ°æ±¾£¬È·±£°æ±¾´òÔÚ°üÖÐ
SDK_VERSION=0.0.1
# ÒµÎñsdkµÄupload_artifact_id
SDK_ARTIFACT_ID=MY-SAMPLES-SDK
1.2 ÔÚ sdk build.gradle ÖмÓÈëÅäÖà Ìæ»»ÔÓÐµÄ apply plugin: 'com.android.library'
//×¢Ò⣡£¡Ò»¶¨Òª·ÅÔÚÎļþ×îÇ°Ãæ
// apply plugin±íʾ¸ÃÏîÄ¿»áʹÓÃÖ¸¶¨µÄ²å¼þ,sdk¶ÔÓ¦µÄÊÇcom.android.library
if (isAppModule.toBoolean()) {
apply plugin: 'com.android.application'
if (isPatchModule.toBoolean()) {
//ÖÆ×÷²¹¶¡Ê±½«Õâ¸ö´ò¿ª£¬auto-patch-plugin½ô¸ú×Åcom.android.application
apply plugin: 'auto-patch-plugin'
}
apply plugin: 'robust'
} else {
apply plugin: 'com.android.library'
}
apply from: rootProject.getRootDir().getAbsolutePath() + "/packPlugin.gradle"
1.3 ¼ÓÈë buildConfigField
// ÊÓÇé¿ö¶ø¶¨£¬Èç¹ûÄãÔÚ³õʼ»¯ÈȸüsdkʱµÄ´«ÈëµÄ°æ±¾ºÅÓÐÁíÍâµÄÈ¡Öµ·½Ê½£¬Ò²¿ÉÒÔ²»¼Ó´ËbuildConfig
android {
defaultConfig {
buildConfigField "String", "SDK_VERSION", "\"${SDK_VERSION}\""
buildConfigField "String", "SDK_ARTIFACT_ID", "\"${SDK_ARTIFACT_ID}\""
}
}
1.4 ÔÚ sdk build.gradle ÖÐÅäÖÃÇ©Ãû
android {
// Ç©ÃûµÄÅäÖÃ
signingConfigs {
debug {
}
// release°æ±¾µÄÇ©Ãû
release {
// Ç©ÃûµÄһЩÐÅÏ¢
keyAlias 'key0'
keyPassword '123456'
storeFile file('./hotfix.jks')
storePassword '123456'
}
}
}
1.5 ÅäÖûìÏý
¸´ÖÆÕ³ÌùÅäÖõ½ sdk build.gradle
android {
buildTypes {
innerTest {
//...
matchingFallbacks = ['debug', 'release']
}
release {
signingConfig signingConfigs.release
minifyEnabled isProguard.toBoolean()//´Ë´¦È¡µÄisProguard¾ÍÊÇ1.1ÔÚÏîÄ¿`gradle.properties`ÖÐÌí¼ÓµÄisProguard¿ª¹Ø
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
// ApplicationºÍLibraryÇåµ¥Îļþ´¦Àí·½Ê½²»Í¬
if (isAppModule.toBoolean()) {
manifest.srcFile 'src/main/debug/AndroidManifest.xml'
} else {
manifest.srcFile 'src/main/release/AndroidManifest.xml'
}
}
}
}
¸´ÖÆÕ³ÌùʾÀýsdkµÄlib-proguard-rules.proµ½ÒµÎñSDK moduleĿ¼Ï£¬ÐÞ¸ÄÎļþÖеİüÃû
½Ó×ÅÅäÖúÃsdk×Ô¼ºµÄ»ìÏý¹æÔò
android {
defaultConfig {
consumerProguardFiles 'lib-proguard-rules.pro'
}
}
2. µ¼¿â
ÔÚ sdk µÄ build.gradle ÖÐÒýÈë¿â
implementation 'com.github.feelschaotic:SDKHotFix:XX-RELEASE'
XXΪ×îÐÂSDK°æ±¾ºÅ£¬ÀýÈçimplementation 'com.github.feelschaotic:SDKHotFix:1.3-RELEASE'
×¢£º×îа汾¼ûREADME±êÖ¾
ÔÚ¸ùÏîÄ¿build.gradleÖмÓÈëmavenÅäÖÃ
repositories {
//½ÓÈëµÚ¶þ²½:Ôö¼ÓmavenÅäÖÃ
maven { url "https://mvnrepository.com/" }
}
...
allprojects {
repositories {
maven { url "https://mvnrepository.com/" }
}
}
ÔÙÌí¼ÓclasspathÅäÖÃ
// ApplicationģʽÏÂÒýÈëRobust½Å±¾²å¼þ
if (isAppModule.toBoolean()) {
classpath 'com.github.feelschaotic:Robust.gradle-plugin:0.4.87.5-RELEASE'
classpath 'com.github.feelschaotic:Robust.auto-patch-plugin:0.4.87.5-RELEASE'
}
4. ¸´ÖÆʾÀýÏîÄ¿µÄ½Å±¾ºÍÎļþ
4.1 ¸´ÖÆ MainActivity.java µ½ sdk module µÄ java\°üÃû Ŀ¼Ï£¨Ä¿µÄÊÇΪÁËapplication´ò°üÅäÖò»±¨´í£©
4.2 ¸´ÖÆ debug ºÍ release 2 ¸öÎļþ¼Ðµ½ main Ŀ¼Ï£¬ÐÞ¸ÄÀïÃæµÄ AndroidManifest.xml£¬¸ü¸ÄΪÄã×Ô¼ºÒµÎñSDKµÄ°üÃû
<manifest package="${packageName}"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
4.3 ¸´ÖÆ robust.xml µ½sdk module ¸ùĿ¼£¬¸ü¸ÄÏ°üÃû
4.4 ¸´ÖÆ packPlugin.gradle µ½ÏîÄ¿µÄ¸ùĿ¼
5. ³õʼ»¯Èȸü¿â
val config: HotfixConfig = HotfixConfig.Builder().debug(true)
.appVersion(BuildConfig.VERSION_NAME)
.packageName(BuildConfig.APPLICATION_ID)
.build()
HotfixManager.init(application, config)
6. Ìí¼ÓȨÏÞ
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
7. ¼ÓÈë»ìÏý
-keep class com.alibaba.sdk.android.oss.** { *; }
-dontwarn okio.**
-dontwarn org.apache.commons.codec.binary.**
- PC¹Ù·½°æ
- °²×¿¹Ù·½ÊÖ»ú°æ
- IOS¹Ù·½ÊÖ»ú°æ