赞
踩
apply plugin: 'com.tencent.bugly.tinker-support' def bakPath = file("${buildDir}/bakApk/")/*** 此处填写每次构建生成的基准包目录* 使用Gradle/BuglyDemo/app/Tasks/build/assembleRelease 指令生成* 存储到app/build/bakApk/对应时间点的目录中*/def baseApkDir = "app-1102-11-02-28" /** * 对于插件各参数的详细解析请参考 */ tinkerSupport { // 开启tinker-support插件,默认值true enable = true // 指定归档目录,默认值当前module的子目录tinker autoBackupApkDir = "${bakPath}" // 是否启用覆盖tinkerPatch配置功能,默认值false // 开启后tinkerPatch配置不生效,即无需添加tinkerPatch overrideTinkerPatchConfiguration = true // 编译补丁包时,必需指定基线版本的apk,默认值为空 // 如果为空,则表示不是进行补丁包的编译 // @{link tinkerPatch.oldApk } baseApk = "${bakPath}/${baseApkDir}/app-release.apk" // 对应tinker插件applyMapping baseApkProguardMapping = "${bakPath}/${baseApkDir}/app-release-mapping.txt" // 对应tinker插件applyResourceMapping baseApkResourceMapping = "${bakPath}/${baseApkDir}/app-release-R.txt" // 构建基准包和补丁包都要指定不同的tinkerId,并且必须保证唯一性 tinkerId = "patch-2.3.0_2" // 构建多渠道补丁时使用 // buildAllFlavorsDir = "${bakPath}/${baseApkDir}" // 是否启用加固模式,默认为false.(tinker-spport 1.0.7起支持) // isProtectedApp = true // 是否开启反射Application模式 enableProxyApplication = true } /** * 一般来说,我们无需对下面的参数做任何的修改 * 对于各参数的详细介绍请参考: * 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" // 可选,设置mapping文件,建议保持旧apk的proguard混淆方式 //applyResourceMapping = "${bakPath}/${appName}/app-release-R.txt" // 可选,设置R.txt文件,通过旧apk文件保持ResId的分配 } }
/** * @author Lixm * @date 2017/7/6 * @detail * 自定义Application. * * 注意:这个类集成TinkerApplication类,这里面不做任何操作,所有Application的代码都会放到ApplicationLike继承类当中<br/> * <pre> * 参数解析: * 参数1:int tinkerFlags 表示Tinker支持的类型 dex only、library only or all suuport,default: TINKER_ENABLE_ALL * 参数2:String delegateClassName Application代理类 这里填写你自定义的ApplicationLike * 参数3:String loaderClassName Tinker的加载器,使用默认即可 * 参数4:boolean tinkerLoadVerifyFlag 加载dex或者lib是否验证md5,默认为false * </pre> */ public class MyApplication extends TinkerApplication { public MyApplication() { super(ShareConstants.TINKER_ENABLE_ALL, "com.lixm.animationdemo.application.MyApplicationLike", "com.tencent.tinker.loader.TinkerLoader", false); } }
@Override public void onCreate() { super.onCreate(); setDatabase(); //对xUtils进行初始化 x.Ext.init(getApplication()); //是否是开发、调试模式 x.Ext.setDebug(true, true);//是否输出debug日志,开启debug会影响性能 //设置是否开启热更新能力,默认为true Beta.enableHotfix = true; //设置是否自动下载补丁,默认为true Beta.canAutoDownloadPatch = true; //设置是否自动合成补丁,默认为true Beta.canAutoPatch = true; //设置是否提示用户重启,默认为false Beta.canNotifyUserRestart = true; //补丁回调接口 Beta.betaPatchListener = new BetaPatchListener() { @Override public void onPatchReceived(String patchFile) { LogUtil.w("补丁下载地址:"+patchFile); Toast.makeText(getApplication(), "补丁下载地址:" + patchFile, Toast.LENGTH_SHORT).show(); } @Override public void onDownloadReceived(long savedLength, long totalLength) { Toast.makeText(getApplication(), String.format(Locale.getDefault(), "%s %d%%", Beta.strNotificationDownloading, (int) (totalLength == 0 ? 0 : savedLength * 100 / totalLength)), Toast.LENGTH_SHORT).show(); } @Override public void onDownloadSuccess(String msg) { Toast.makeText(getApplication(), "补丁下载成功:"+msg, Toast.LENGTH_SHORT).show(); LogUtil.w("补丁下载成功:"+msg); } @Override public void onDownloadFailure(String msg) { Toast.makeText(getApplication(), "补丁下载失败:"+msg, Toast.LENGTH_SHORT).show(); LogUtil.w("补丁下载失败:"+msg); } @Override public void onApplySuccess(String msg) { Toast.makeText(getApplication(), "补丁应用成功:"+msg, Toast.LENGTH_SHORT).show(); LogUtil.w("补丁应用成功:"+msg); } @Override public void onApplyFailure(String msg) { Toast.makeText(getApplication(), "补丁应用失败:"+msg, Toast.LENGTH_SHORT).show(); LogUtil.w("补丁应用失败:"+msg); } @Override public void onPatchRollback() { LogUtil.w("==============onPatchRollback======"); } }; //设置开发设备,默认为false,上传补丁如果下发范围指定为"开发设备",需要调用此接口来标识开发设备 Bugly.setIsDevelopmentDevice(getApplication(), true); //这里实现SDK初始化,appId替换成你的在Bugly平台申请的appId Bugly.init(getApplication(), "5ca40d59fb", true); // Bugly.init(getApplication(), "900029763", true); instance=this; } @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); // TODO: 安装tinker Beta.installTinker(this); } @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void registerActivityLifecycleCallback( Application.ActivityLifecycleCallbacks callbacks) { getApplication().registerActivityLifecycleCallbacks(callbacks); }
@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); // you must install multiDex whatever tinker is installed! MultiDex.install(base); // 安装tinker Beta.installTinker(); }
<activity android:name="com.tencent.bugly.beta.ui.BetaActivity" android:configChanges="keyboardHidden|orientation|screenSize|locale" android:theme="@android:style/Theme.Translucent" /> <provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileProvider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" /> </provider>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。