一、问题报错
在生成APK时报错,显示无法读取jks,考虑多方面原因,配置方面没有问题。最后发现由于旧版工程的Java版本与当前AS默认的Java版本不一致,所以需要升级工程版本才行。
二、解决方法
1、build.gradle文件修改如下,主要将插件版本从3.6.1升级到7.4.2:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'https://www.jitpack.io' }
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
}
dependencies {
classpath "com.android.tools.build:gradle:7.4.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url 'https://www.jitpack.io' }
maven { url 'https://maven.aliyun.com/repository/public' }
maven { url 'https://maven.aliyun.com/repository/central' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2、gradle-wrapper.properties文件如下,主要将gradle-5.6.4-all更换为gradle-8.2-bin:
#Tue Dec 01 18:43:40 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://mirrors.cloud.tencent.com/gradle//gradle-8.2-bin.zip
3、删掉.gradle和.idea文件夹后,重新build,等待构建成功。
4、重新生成APK。
5、遇到下面的报错,由于Manifest中api版本过低导致,需要声明android:exported="true"
Manifest merger failed : android:exported needs to be explicitly specified for element <activity#edu.cn.bookadminister.app.WelcomeActivity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
具体修改如下:
<activity android:name=".app.WelcomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
重新生成APK,成功!
让无数人从黑暗走向光明的书籍,你的命运可能由此改变: