No more nonsense. We must have compared the advantages and disadvantages.
If you don't know what a hot update is You can baidu by yourself
This doesn't mean to belittle any company. Now we all want to find a simple and fast integration method So I decided to be obedient and not lose, hahaha
I had a problem before I started. The official work order hasn't given me a solution before I send the document Patches cannot be generated for packages printed on higher versions Always stuck building , so the current method is to reduce the version Mine was 7 + It was changed to 3+ so if you have a higher version of brother Meng, you should pay attention
Well, then we'll enter the formal pit climbing Road,
1. First, log in to alicloud to register an account and create an application
Enter the app package name and create the app
Download relevant configuration files by location Put it where it should be
The next step is to put the code in the specified location
So here comes the question... Some people say it's OK to just press the official documents. Why do you have to read these articles
Hehe, it's small Brother, you're too young
Now listen to me carefully Here, you need to use some parameters to configure the application registration on alicloud
two Everyone should use AS Next, I'll post all the documents Please check it yourself
build.gradle for the project
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() mavenCentral() // maven { // url 'https://maven.aliyun.com/nexus/content/repositories/releases/' // } } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' // Add EMAS services plug-in // classpath 'com.aliyun.ams:emas-services:1.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() maven { url 'https://jitpack.io' } // maven {url 'http://maven.aliyun.com/nexus/content/repositories/releases/'} // maven{ url 'http://maven.aliyun.com/nexus/content/repositories/central/'} } } task clean(type: Delete) { delete rootProject.buildDir }
build.gradle of app
plugins { id 'com.android.application' } //apply plugin: 'com.aliyun.ams.emas-services' android { compileSdkVersion 28 buildToolsVersion "29.0.0" defaultConfig { applicationId "com.example.demotestaliemas" minSdkVersion 16 targetSdkVersion 28 versionCode 1 versionName "1.0.8" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } repositories { maven { url "https://maven.aliyun.com/nexus/content/repositories/releases" } } dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' implementation 'com.aliyun.ams:alicloud-android-hotfix:3.3.0' implementation 'com.github.tbruyelle:rxpermissions:0.10.2' implementation 'io.reactivex.rxjava2:rxjava:2.0.4' implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' implementation 'cn.pedant.sweetalert:library:1.3' }
Next is our confusion file Proguard-rules.pro
Note that the document says that a mapping.txt file will be generated but I didn't! I didn't! I didn't!
#The baseline package is used to generate mapping.txt -printmapping mapping.txt #The generated mapping.txt is moved to the / APP path under the app/build/outputs/mapping/release path #Use the repaired items to ensure consistent confusion results #-applymapping mapping.txt #hotfix -keep class com.taobao.sophix.**{*;} -keep class com.ta.utdid2.device.**{*;} #Prevent inline -dontoptimize
There are no code snippets in the activity However, you can modify some text in the xml file or add an image to test the effect when generating the patch package later
oh Android 6.0 remember to get permission
Here's the point:
Here's the point:
Here's the point:
Here's the point:
public class SophixStubApplication extends SophixApplication { private final String TAG = "SophixStubApplication"; // Here, SophixEntry should specify the real Application and ensure that the realapplicationsub class name is not confused. @Keep @SophixEntry(MyRealApplication.class) static class RealApplicationStub {} @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); // If you need to use MultiDex, you need to call it here. // MultiDex.install(this); initSophix(); } private void initSophix() { String appVersion = "0.0.0"; try { appVersion = this.getPackageManager() .getPackageInfo(this.getPackageName(), 0) .versionName; } catch (Exception e) { } final SophixManager instance = SophixManager.getInstance(); instance.setContext(this) .setAppVersion(appVersion) .setSecretMetaData("Fill in your own", "Fill in your own", "Fill in your own") .setEnableDebug(true) .setEnableFullLog() .setPatchLoadStatusStub(new PatchLoadStatusListener() { @Override public void onLoad(final int mode, final int code, final String info, final int handlePatchVersion) { if (code == PatchStatus.CODE_LOAD_SUCCESS) { Log.i(TAG, "sophix load patch success!"); } else if (code == PatchStatus.CODE_LOAD_RELAUNCH) { // If you need to restart in the background, it is recommended to save the status here with SharePreference. Log.i(TAG, "sophix preload patch success. restart app to make effect."); } } }).initialize(); } }
Then you'll find MyRealApplication.class It's red never mind Let's build a new one
public class MyRealApplication extends Application { @Override public void onCreate() { super.onCreate(); //hot fix. Load patch from aliyun service. SophixManager.getInstance().queryAndLoadNewPatch(); } }
Remember to add sophixstabapplication to the application in the manifest file
There are also permissions:
<!-- network right--> <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" /> <!--External storage read permission is required for debugging tools to load local patches--> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
There are also configured parameters:
<meta-data android:name="com.taobao.android.hotfix.IDSECRET" android:value="Fill in your own" /> <meta-data android:name="com.taobao.android.hotfix.APPSECRET" android:value="Fill in your own" /> <meta-data android:name="com.taobao.android.hotfix.RSASECRET" android:value="Fill in your own"/>
Now that the code is written, the next step is to package the new package and distinguish the old package. For example, the new package loads more imgview s than the old package, mainly to test the effect
Give you five minutes to pack. I'll go out for a cigarette
All right, let's go on
Next, it's time to generate the patch package. Note that some parameters should be set before generating the patch package
After the parameters are set, the new package Add old package path click GO!
Wait another 1-2 minutes When do you go out for a cigarette
sopjix-patch.jar is the patch package we generated
Finally, throw the newly patched package to the Alibaba cloud platform
Add version -- upload version
OK -- "publish"
Create new publication select publication type OK
So far, the whole process is completed You can test your Kung Fu with cigarettes Install an older App first
After opening, kill the process and reopen it later See if the picture or text has been loaded
All right, it's over We have 20 minutes to get off work Have another cigarette
Oh, yes You can download the demo to view
10 minutes from work...
For the hard work of bloggers Please give me a little praise