Android Bugly's pits of practice

Keywords: Gradle network Android SDK

The last article talked about how to use tinker. Today we bring a more convenient sdk. It also uses Tinker to achieve hot updates. It also adds a background management patch. Is it more convenient, and it also reduces many of our Tinker configurations?

  • Configure build.gradle for the main project and app project. To separate the configuration, create a new tinker-support.gradle
  • Revamping Application
  • Generate the benchmark app, that is, the APK with the bug version (remember to notify the network, that is, the network opens the app,bugly uploads the version number to the background database)
  • For the benchmark version of apk, patch_singed_7zip.apk is generated.
  • Bugly Upload Patch File
  • After opening app, restart app, and you can see the fix

    Configure build.gradle for the main project and app project, and create a new tinker-support.gradle to separate the configuration.

build.gradle:

 classpath "com.tencent.bugly:tinker-support:latest.release"

Project build.gradle:

//hot fix
    compile "com.android.support:multidex:1.0.1" // Multiple dex configuration
    //Annotate the original bugly warehouse
    //compile 'com.tencent.bugly:crashreport:latest.release'//Latt.releaseReferring to the latest version number, you can also specify a specific version number, such as2.3.2
    compile 'com.tencent.bugly:crashreport_upgrade:latest.release'//Latt.releaseReferring to the latest version number, you can also specify a specific version number, such as1.2.0
    compile 'com.tencent.bugly:nativecrashreport:latest.release' //Latt.releaseReferring to the latest version number, you can also specify a specific version number, such as2.2.0

Note: By the way, the debug and release signature files are also configured.

 signingConfigs {
        release {
            try {
                storeFile file('E:/androidstudioWorkPace/FanliMall/fanlimall.jks')
                storePassword "123456"
                keyAlias "FanLi_mall"
                keyPassword "123456"
            } catch (ex) {
                throw new InvalidUserDataException(ex.toString())
            }
        }
        debug {
            keyAlias 'FanLi_mall'
            keyPassword '123456'
            storeFile file('E:/androidstudioWorkPace/FanliMall/fanlimall.jks')
            storePassword '123456'
        }
    }

 buildTypes {
        release {
            minifyEnabled false
            signingConfig signingConfigs.debug
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            signingConfig signingConfigs.debug
        }
    }
       sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }

Create a new tinker-support.gradle file to configure tinker and add build.gradle to your model.
Attention should be paid to:
Def base ApkDir = fanli-0522-11-02-36 refers to the folder where you store the base apk.
baseApk = "bakPath/{baseApkDir}/fanli-release.apk" is the name of your benchmark APK and should correspond.
tinkerId = "patch-5.1.2" refers to the unique identification number of the current benchmark apk, which needs to be modified when it is regenerated into a patch.
Whether enableProxyApplication = false opens reflection or not by default requires us to manually modify the application so that compatibility will be improved.

// Dependent plug-in scripts
apply from: 'tinker-support.gradle'

tinker-support.gradle:

apply plugin: 'com.tencent.bugly.tinker-support'

def bakPath = file("${buildDir}/bakApk/")

/**
 * Fill in the base package directory generated for each build here
 */
def baseApkDir = "fanli-0522-11-02-36"

/**
 * For detailed analysis of plug-in parameters, please refer to
 */
tinkerSupport {

    // Open the tinker-support plug-in with the default value true
    enable = true

    // Specify the archive directory, default value of current module subdirectory tinker
    autoBackupApkDir = "${bakPath}"

    // Whether to enable overlay tinkerPatch configuration function, default value false
    // The tinkerPatch configuration does not take effect after opening, that is, there is no need to add tinkerPatch
    overrideTinkerPatchConfiguration = true

    // When compiling patch packs, you must specify the baseline version of the apk, which defaults to null
    // If null, it means that the patch package is not compiled
    // @{link tinkerPatch.oldApk }
    baseApk = "${bakPath}/${baseApkDir}/fanli-release.apk"

    // applyMapping corresponding to tinker plug-in
    baseApkProguardMapping = "${bakPath}/${baseApkDir}/app-release-mapping.txt"

    // ApplyResource Mapping for the tinker plug-in
    baseApkResourceMapping = "${bakPath}/${baseApkDir}/app-release-R.txt"

    // Constructing benchmark and patch packs specifies different tinkerId and must guarantee uniqueness
    tinkerId = "patch-5.1.2"

    // Use when building multi-channel patches
    // buildAllFlavorsDir = "${bakPath}/${baseApkDir}"

    // Whether the reinforcement mode is enabled or not, default is false.(tinker-spport 1.0.7 support)
    // isProtectedApp = true

    // Whether to turn on Reflective Application mode
    enableProxyApplication = false

}

/**
 * Generally speaking, we do not need to make any changes to the following parameters
 * For a detailed description of each parameter, please refer to:
 * https://github.com/Tencent/tinker/wiki/Tinker-%E6%8E%A5%E5%85%A5%E6%8C%87%E5%8D%97
 */
tinkerPatch {
    //oldApk ="${bakPath}/${appName}/app-release.apk"
    ignoreWarning = false
    useSign = true
    dex {
        dexMode = "jar"
        pattern = ["classes*.dex"]
        loader = []
    }
    lib {
        pattern = ["lib/*/*.so"]
    }

    res {
        pattern = ["res/*", "r/*", "assets/*", "resources.arsc", "AndroidManifest.xml"]
        ignoreChange = []
        largeModSize = 100
    }

    packageConfig {
    }
    sevenZip {
        zipArtifact = "com.tencent.mm:SevenZip:1.1.10"
//        path = "/usr/local/bin/7za"
    }
    buildConfig {
        keepDexApply = false
        //tinkerId = "1.0.1-base"
        //applyMapping = "${bakPath}/${appName}/app-release-mapping.txt"// Optional. Set up the mapping file. It is recommended that the proguard confusion of the old apk be maintained.
        //applyResourceMapping = "${bakPath}/${appName}/app-release-R.txt"// Optional, set the R.txt file, and keep ResId allocation through the old apk file
    }
}

Revamp Application, where I chose enableProxyApplication = false, manual revamp

Inherit Default Application Like, the main three methods.
Here's a note: when you upload patches, choose the download device to have development, full, custom selection. If you choose the development device, check if you call Bugly. setIs Development Device (getApplication Context (), true);
Otherwise, you won't receive the patch update. It's a pit.

  @Override
    public void onCreate() {
        super.onCreate();
        // SDK initialization is implemented here, and appId is replaced by your appId applied for on the Bugly platform.
        // When debugging, change the third parameter to true
        Bugly.init(getApplication(), "900029763", false);
        Bugly.setIsDevelopmentDevice(getApplicationContext(), true);
        //
        //Transfer the oncreate code from your Application here
    }


    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    @Override
    public void onBaseContextAttached(Context base) {
        super.onBaseContextAttached(base);
        // you must install multiDex whatever tinker is installed!
        MultiDex.install(base);

        // Install tinker
        // TinkerManager.installTinker(this); replace with the method provided by Bugly below
        Beta.installTinker(this);
    }

    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public void registerActivityLifecycleCallback(Application.ActivityLifecycleCallbacks callbacks) {
        getApplication().registerActivityLifecycleCallbacks(callbacks);
    }

Inheritance of TinkerApplication
The construction method has four parameters.
The first is the type of patch you need to modify. There are resource files, classes and so on. Select all of them here.
The second one is the Application Like we modified above, which needs the full package name.
The latter two defaults.
Finally, remember to configure the Tinker Application in Android Manifest. xml.

public class MyApplicationLike extends TinkerApplication {
    public MyApplicationLike() {
        super(ShareConstants.TINKER_ENABLE_ALL, "interest.fanli.app.FanLiBaseApplication",
                "com.tencent.tinker.loader.TinkerLoader", false);
    }


}

Generate the benchmark app, that is, the APK with the bug version (remember to notify the network, that is, the network opens the app,bugly uploads the version number to the background database)

Packaging signature apk with gradle tool

Build success, generate the apk file (base version)

For the benchmark version of apk, patch_singed_7zip.apk is generated.

In tinker-support.gradle
1,def baseApkDir = "fanli-0522-11-02-36"
The folder corresponding to your base version
2,baseApk = "bakPath/{baseApkDir}/fanli-release.apk"
Name of apk
3.tinkerId = "patch-5.1.2"
Modify tinkerId as long as it is different from the base version.
(Configuration is also required if confusion is turned on:

  // applyMapping corresponding to tinker plug-in
    baseApkProguardMapping = "${bakPath}/${baseApkDir}/app-release-mapping.txt"

    // ApplyResource Mapping for the tinker plug-in
    baseApkResourceMapping = "${bakPath}/${baseApkDir}/app-release-R.txt"

)

Generation using tinker-support

Patch file path: build outputs patch release patch_signed_7zip. apk
Note that it's in the patch path, not in the tinker Patch.

After online reporting, Bugly uploads the patch file, choosing all the devices. If you are developing the device, remember to add Bugly. setIs Development Device (getApplication Context (), true).

Restart app (about 2 reboots) and you can fix it

bugly video teaching access

Common Questions and Documentation

Posted by micki on Fri, 28 Jun 2019 15:58:19 -0700