自我更新时,出现解析错误。但是,如果我从url new apk在设备上下载,则安装成功。第一个和第二个apk会唱歌,我尝试签名调试apk并意识到,但也无法正常工作。 New JarFile(path)返回Jar文件,没关系。下载的文件中的哈希值等于原始文件。我的通话意图在那里更新:
Intent promptInstall = new Intent(Intent.ACTION_VIEW);
promptInstall.setDataAndType(Uri.fromFile(new File(location + "update.apk")), "application/vnd.android.package-archive");
promptInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
promptInstall.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Constants._context.startActivity(promptInstall);
清单权限:
<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.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Grandle设置:
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias '****'
keyPassword '*****'
storeFile file('*****')
storePassword '*****'
}
}
compileSdkVersion 27
defaultConfig {
applicationId "******"
minSdkVersion 23
targetSdkVersion 27
versionCode 4
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.config
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
signingConfig signingConfigs.config
}
}
productFlavors {
}
buildToolsVersion '27.0.3'
}
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.4.0-RC1'
implementation 'com.google.code.gson:gson:2.2.4'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
}