Meituan-Dianping / walle

Android Signature V2 Scheme签名下的新一代渠道包打包神器
Apache License 2.0
6.77k stars 1.08k forks source link

Error:Plugin requires 'APK Signature Scheme v2 Enabled' for sourceSets. 怎么解决啊 #180

Closed zhengzhuoxing closed 6 years ago

achellies commented 6 years ago

加上--stacktrace把详细的日志信息发出来, 一般这种情况是未开启V2签名或者V2签名被破坏了

achellies commented 6 years ago
            if (!isV2SignatureSchemeEnabled(variant)) {
                throw new ProjectConfigurationException("Plugin requires 'APK Signature Scheme v2 Enabled' for ${variant.name}.", null);
            }
zhengzhuoxing commented 6 years ago

14:17 Executing tasks: [:API:generateDebugSources, :API:mockableAndroidJar, :API:prepareDebugUnitTestDependencies, :API:generateDebugAndroidTestSources, :BaseUI:generateDebugSources, :BaseUI:mockableAndroidJar, :BaseUI:prepareDebugUnitTestDependencies, :BaseUI:generateDebugAndroidTestSources, :StudentApp:generateDebugSources, :StudentApp:generateDebugAndroidTestSources, :StudentApp:mockableAndroidJar, :StudentApp:prepareDebugUnitTestDependencies, :TeacherApp:generateDebugSources, :TeacherApp:generateDebugAndroidTestSources, :TeacherApp:mockableAndroidJar, :TeacherApp:prepareDebugUnitTestDependencies, :androidtagview:generateDebugSources, :androidtagview:mockableAndroidJar, :androidtagview:prepareDebugUnitTestDependencies, :androidtagview:generateDebugAndroidTestSources, :ptrRefreshlibrary:generateDebugSources, :ptrRefreshlibrary:generateDebugAndroidTestSources, :ptrRefreshlibrary:mockableAndroidJar, :ptrRefreshlibrary:prepareDebugUnitTestDependencies]

14:22 Gradle build finished with 1 warnings(s) in 4m 54s 655ms

14:23 Gradle sync started

14:23 Gradle sync failed: Plugin requires 'APK Signature Scheme v2 Enabled' for sourceSets. Consult IDE log for more details (Help | Show Log)

15:29 Gradle sync started

15:29 Gradle sync failed: Plugin requires 'APK Signature Scheme v2 Enabled' for sourceSets. Consult IDE log for more details (Help | Show Log)

zhengzhuoxing commented 6 years ago

Signature Scheme v2 Enabled 在gradle2.2之后是自动开启的不是么

zhengzhuoxing commented 6 years ago

Android 7.0 引入一项新的应用签名方案 APK Signature Scheme v2,它能提供更快的应用安装时间和更多针对未授权 APK 文件更改的保护。在默认情况下,Android Studio 2.2 和 Android Plugin for Gradle 2.2 会使用 APK Signature Scheme v2 和传统签名方案来签署您的应用。 我并没有手动去关闭它啊

achellies commented 6 years ago

build.gradle里开启V2签名了吗?或者把walle注释掉,打一个包看看是否有签名区(在Apk文件中通过字符串查找 “APK Sig Block 42”)

zhengzhuoxing commented 6 years ago

在Apk中有 APK Sig Block 42PK,但是我这还是提示未开启 APK Signature Scheme v2

achellies commented 6 years ago
       project.afterEvaluate {
            project.android.applicationVariants.all { BaseVariant variant ->
                def variantName = variant.name.capitalize();

                if (!isV2SignatureSchemeEnabled(variant)) {
                    throw new ProjectConfigurationException("Plugin requires 'APK Signature Scheme v2 Enabled' for ${variant.name}.", null);
                }

            }
        }

 boolean isV2SignatureSchemeEnabled(BaseVariant variant) throws GradleException {
        def signingConfig = getSigningConfig(variant);
        if (signingConfig == null || !signingConfig.isSigningReady()) {
            return false;
        }

        // check whether APK Signature Scheme v2 is enabled.
        if (signingConfig.hasProperty("v2SigningEnabled") &&
                signingConfig.v2SigningEnabled == true) {
            return true;
        }

        return false;
    }

这个是判断逻辑, 把这段贴到项目的build.gradle中跑下看看是否会出错

zhengzhuoxing commented 6 years ago

BaseVariant 找不到

achellies commented 6 years ago

com.android.build.gradle.api.BaseVariant

zhengzhuoxing commented 6 years ago

把这段代码添加上之后 还是报 这个错 Error:Plugin requires 'APK Signature Scheme v2 Enabled' for sourceSets.

achellies commented 6 years ago
SigningConfig getSigningConfig(BaseVariant variant) {
        return variant.buildType.signingConfig == null ? variant.mergedFlavor.signingConfig : variant.buildType.signingConfig;
    }
 def signingConfig = getSigningConfig(variant);
        if (signingConfig == null || !signingConfig.isSigningReady()) {
            return false;
        }

        // check whether APK Signature Scheme v2 is enabled.
        if (signingConfig.hasProperty("v2SigningEnabled") &&
                signingConfig.v2SigningEnabled == true) {
            return true;
        }

        return false;

这个条件满足吗?

zhengzhuoxing commented 6 years ago

Error:(102, 0) Could not find method getSigningConfig() for arguments [com.android.build.gradle.internal.api.ApplicationVariantImpl_Decorated@7c88a66e] on project 找不到这个方法

achellies commented 6 years ago

加上这个

SigningConfig getSigningConfig(BaseVariant variant) {
        return variant.buildType.signingConfig == null ? variant.mergedFlavor.signingConfig : variant.buildType.signingConfig;
    }
zhengzhuoxing commented 6 years ago

1512984230 1 是不是说明我开启 v2了

zhengzhuoxing commented 6 years ago

我用命令行打包了,不用配置gradle了 谢谢你的帮助

jack-github commented 6 years ago

这个问题怎么解决的啊?