我正在开发支持 MirrorLink 的 Android 应用程序,并在使用 Google 开发人员密钥签署 APK 后遇到 Mirrorlink 检查“应用程序 ID”的问题。
我已经为 Android Studio 创建了使用 Mirrorlink 插件生成的空项目,它创建了 Gradle 任务,允许生成.crt
带有 Mirrorlink 相关配置信息的文件。我只是将此脚本复制到build.gradle
主应用程序模块中我自己的文件中。但是 Mirrorlink-aware 应用程序验证器显示签名 APK 错误(发布到 Google Play 的标准应用程序签名),而如果 APK 未签名则不会发现任何问题。
如何发现应用签名后出现的问题?
我尝试了什么:1)将 Gradle 脚本与Mirrorlink 提供的示例应用程序对齐- 不走运。
2)插入v1SigningEnabled false
和v2SigningEnabled false
- 没有运气。
3) 签名和未签名 APK 的 Gradle 输出是相同的,除了输出文件名和> Task :app:validateSigningRelease
任务。
AndroidManifest.xml Mirrorlink 相关截图:
<uses-permission android:name="com.mirrorlink.android.service.ACCESS_PERMISSION"/>
<intent-filter>
<action android:name="com.mirrorlink.android.app.LAUNCH"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="com.mirrorlink.android.app.TERMINATE"/>
<category android:name="android.intent.category.DEFAULT"/>
应用模块的build.gradle:
def generateSelfSignedCertificate(version){
def buildType = version == "release" ? "assembleRelease": "assembleDebug"
def rerunAssemble = true
def projectLocation = projectDir.toString()
def certGeneratorLocation = "certificategenerator-android-studio.jar"
def certXmlLocation = projectLocation + "/certificate.xml"
def certificateDestination = projectLocation + "/src/main/assets/self-signed.ccc.crt"
def certificateFolder = projectLocation + "/src/main/assets/"
def certificateIssuer = "CN=SELF-SIGNED"
def developerId = ""
def apkLocation = ""
android.applicationVariants.all { variant ->
if ((variant.name).equals(version)) {
variant.outputs.each { output ->
//noinspection GrReassignedInClosureLocalVar
apkLocation = output.outputFile
}
}
}
if (project.hasProperty("isLast")) {
rerunAssemble = !isLast
}
if (rerunAssemble) {
def subdir = new File(certificateFolder)
if( !subdir.exists() ) {
subdir.mkdirs()
}
exec {
executable 'java'
args "-jar", certGeneratorLocation, "generate-certificate", apkLocation,
android.defaultConfig.applicationId, android.defaultConfig.versionCode,
certXmlLocation, certificateDestination, certificateIssuer, developerId
println(args)
}
if (System.properties['os.name'].toLowerCase().contains("windows")) {
exec {
executable "cmd"
workingDir projectLocation
args "/c", "..\\gradlew.bat", buildType, "-PisLast=true"
}
} else {
exec {
executable "bash"
workingDir projectLocation
args "../gradlew", buildType, "-PisLast=true"
}
}
}
}
android {
.....
signingConfigs {
storeFile = 'sign.keyStorePath')
keyAlias = 'sign.keyAlias'
storePassword = 'sign.storePassword'
keyPassword = 'sign.keyPassword'
}
}
afterEvaluate {
if (this.hasProperty("assembleRelease")){
assembleRelease.finalizedBy generateSelfSignedCertificateForRelase
}
}
task generateSelfSignedCertificateForRelase {
doLast {
generateSelfSignedCertificate("release")
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}
....
}
运行“assesbleRelease”没有问题 - 它生成带有 Mirrorlink 应用程序 ID 的 .crt 文件。但是如果我把这个文件放在“Mirrorlink-aware application validator”中——它会显示错误报告,如下:
Checking com.mirrorlink.android.app.LAUNCH intent - OK
Checking com.mirrorlink.android.app.TERMINATE intent - OK
Checking com.mirrorlink.android.service.ACCESS_PERMISSION permission - OK
Checking DEVELOPER entity - INCONCLUSIVE. DEVELOPER entity not found
Checking if developer certificate exists for serverID="" - INCONCLUSIVE. DEVELOPER entity not found
Checking application id - FAIL. Calculated application ID doesn't mach id provided in self signed certificate
Checking self signed certificate - OK
The APK is not configured correctly.
但是,如果我删除字符串signingConfig signingConfigs.release
,验证器不会发现任何问题:
Checking com.mirrorlink.android.app.LAUNCH intent - OK
Checking com.mirrorlink.android.app.TERMINATE intent - OK
Checking com.mirrorlink.android.service.ACCESS_PERMISSION permission - OK
Checking DEVELOPER entity - INCONCLUSIVE. DEVELOPER entity not found
Checking if developer certificate exists for serverID="" - INCONCLUSIVE. DEVELOPER entity not found
Checking application id - OK
Checking self signed certificate - OK
The APK is correctly configured as a MirrorLink Aware application.