android 9安装教程,android 9.x 实现应用内更新安装

折腾了3天,总算解决了问题。

依赖如下

implementation 'androidx.core:core:1.0.2'

// implementation 'com.android.support:support-compat:28.0.0'

support包,试了几个版本总是提示一堆

Duplicate class android.support.v4. ……

切换到依赖 androidx,则不能忘记在 androidManifest.xml中替换 name值

android:theme="@style/AppTheme"

android:networkSecurityConfig="@xml/network_security_config"

>

android:name="androidx.core.content.FileProvider"

android:exported="false"

android:grantUriPermissions="true" >

android:name="android.support.FILE_PROVIDER_PATHS"

android:resource="@xml/filepath" />

工具类如下

public static voidinstallApk(Activity activity, File apkFile){

Intent intent=newIntent();

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//Uri uri = Uri.fromFile(apkFile);

Uri uri = null;//todo N FileProvider

//todo O install permission

if(Build.VERSION.SDK_INT >=Build.VERSION_CODES.N){

uri= androidx.core.content.FileProvider.getUriForFile(activity,activity.getPackageName()+".fileprovider", apkFile);

intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

}else{

uri=Uri.fromFile(apkFile);

}

intent.setDataAndType(uri,"application/vnd.android.package-archive");

activity.startActivity(intent);

}

另外为了单纯一点,避免错误提示

Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1)

Duplicate class android.support.v4.app.INotificationSideChannel$Stub foundin modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1)

Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy foundin modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1)

Duplicate class android.support.v4.os.IResultReceiver foundin modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1)

Duplicate class android.support.v4.os.IResultReceiver$Stub foundin modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1)

Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy foundin modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1)

Duplicate class android.support.v4.os.ResultReceiver foundin modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1)

Duplicate class android.support.v4.os.ResultReceiver$1 found in modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1)

Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver foundin modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1)

Duplicate class android.support.v4.os.ResultReceiver$MyRunnable foundin modules classes.jar (androidx.core:core:1.0.2) and classes.jar (com.android.support:support-compat:25.3.1)

Go to the documentation to learn how to Fix dependency resolution errors.

解决办法为,在gradle.properties中添加如下代码

android.useAndroidX=trueandroid.enableJetifier=true

最后贴一下 androidManifest.xml中提到的2个xml文件,在res/xml文件夹下

network_security_config.xml

filepath.xml

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值