ha-excited / bignews Goto Github PK
View Code? Open in Web Editor NEWAndroid增量更新框架差分包升级
Android增量更新框架差分包升级
若老版本的APK安装后删除安装包,那就无法与patch合成新的apk,这问题怎么解决
可以用到项目中吗
用的方法3,提示找不到so库,怎么解决?
vivo手机通过patch合并时候会卡主,以至于不能下一步,但是能生成apk,不知什么原因
在5.1的手机上测试成功了,6.0,7.0,8.0全部失败了。
请问多渠道包怎么管理差分升级
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE};
//请求状态码
private static int REQUEST_PERMISSION_CODE = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.guyurumian);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
Log.e("quanxian"," 1");
//if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE, REQUEST_PERMISSION_CODE);
Log.e("quanxian"," ");
//}
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.back_iv:
case R.id.back_tv:
this.finish();
break;
case R.id.guanyu_dafen:
new MyThread1().start();//创建并启动线程 差分
break;
case R.id.guanyu_banben:
new MyThread2().start();//创建并启动线程 合并
break;
case R.id.guanyu_tiaokuan:
Intent intent = new Intent(this, FuwuTiaokuan.class);
startActivity(intent);
break;
}
}
public class MyThread1 extends Thread {//继承Thread类
public void run() {
//重写run方法
/**
* oldApkPath: 老安装包路径
* newApkPath: 新安装包路径
* patchPath: 升级/差分包路径(输出)
* return: 成功返回 true,否则为 false。
* 差分
*/
String oldApkPath = getApplicationContext().getPackageResourcePath();
File sdFile = Environment.getExternalStorageDirectory();
String sdStrings = sdFile.getAbsolutePath();
String sdString = getSystemFilePath(AboutRuMian.this);
Log.e("sdString","="+sdString);
boolean state=false;
File file=new File(sdString + "/app-debug.apk");
if(file.exists()){
Log.e("文件"," 存在");
}else{
Log.e("文件"," 不存在");
}
Log.e("旧文件"," 地址="+oldApkPath);
File file1=new File(oldApkPath);
if(file1.exists()){
Log.e("旧文件"," 存在");
}else{
Log.e("旧文件"," 不存在");
}
try{
state=BigNews.diff(oldApkPath, sdString + "/app-debug.apk", sdStrings + "/patchPath.patch");
}catch (Exception e){
Log.e("差分失败"," ss0");
}
Log.e("state","="+state);
Looper.prepare();
Toast.makeText(AboutRuMian.this,"求差分包",Toast.LENGTH_SHORT).show();
Looper.loop();
if(state){
Log.e("差分成功"," ss");
}else{
Log.e("差分失败"," ss");
}
}
}
private static String getSystemFilePath(Context context) {
String cachePath;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
|| !Environment.isExternalStorageRemovable()) {
cachePath = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath();
// cachePath = context.getExternalCacheDir().getPath();//也可以这么写,只是返回的路径不一样,具体打log看
} else {
cachePath = context.getFilesDir().getAbsolutePath();
// cachePath = context.getCacheDir().getPath();//也可以这么写,只是返回的路径不一样,具体打log看
}
return cachePath;
}
public class MyThread2 extends Thread {//继承Thread类
public void run() {
//重写run方法
/**
* oldApkPath: 老安装包路径
* newApkPath: 新安装包路径(输出)
* patchPath: 升级/差分包路径
* return: 成功返回 true,否则为 false。
* 合并
*/
String oldApkPath = getApplicationContext().getPackageResourcePath();
File sdFile = Environment.getExternalStorageDirectory();
//String sdString = sdFile.getAbsolutePath();
String sdString = getSystemFilePath(AboutRuMian.this);
File file=new File(sdString + "/old_new.patch");
if(file.exists()){
Log.e("文件"," 存在");
}else{
Log.e("文件"," 不存在");
}
boolean state=BigNews.make(oldApkPath, sdString + "/new1.apk", sdString + "/old_new.patch");
Log.e("state"," ="+state);
if(state){
Log.e("合并成功"," s");
File apkfile = new File(sdString+"/new1.apk");
if (!apkfile.exists()) {
return;
}
Intent i = new Intent(Intent.ACTION_VIEW);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // 7.0+以上版本 //跳转安装apk
Uri apkUri = getUriForFile(AboutRuMian.this,
AboutRuMian.this.getApplicationContext().getPackageName() + ".provider", apkfile);
//与manifest中定义的provider中的authorities="com.xinchuang.buynow.fileprovider"保持一致
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
i.setDataAndType(apkUri, "application/vnd.android.package-archive");
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} else {
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setDataAndType(Uri.parse("file://" + apkfile.toString()),
"application/vnd.android.package-archive");
}
AboutRuMian.this.startActivity(i);
}else{
Log.e("合并失败"," ");
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_PERMISSION_CODE) {
for (int i = 0; i < permissions.length; i++) {
Log.e("guanyurumian", "申请的权限为:" + permissions[i] + ",申请结果:" + grantResults[i]);
}
}
}
android 8.0 和andorid 5.1 均合并失败
再次感谢。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.