签名的 APK 不工作,但调试版本工作正常

Signed APK doesn't work but debug version works fine

我将我的 Unity 游戏导出到 android 工作室,因为我使用了太多的 DEX 文件(由于广告网络库)。我可以毫无困难地构建和 运行 调试版本。我可以构建一个已签名的发行版本并将其上传到 Playstore,但游戏在启动时崩溃。 logcat 表示:

FATAL EXCEPTION...
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/gson/Gson

At [java code from an ad network library]

我没有使用混淆器,调试和发布之间的设置除了在发布中将 debuggable 和 Jni debuggable 设置为 false 之外是相同的。依赖项的范围是对所有人的实现(也试过 API 没有任何区别)。

关于 SO 的一些类似问题是说要清理项目并重建,但这对我没有任何帮助。我不确定还能尝试什么。由于某种原因,这些库似乎没有添加到签名的发布版本中,但我不知道为什么。

编辑:

Gradle 根据要求如下:

// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
buildscript {
   repositories {
      jcenter()
      google()
   }

   dependencies {
      classpath 'com.android.tools.build:gradle:3.2.1'
   }
}

allprojects {
   repositories {
      flatDir {
        dirs 'libs'
      }
       google()
   }
}

apply plugin: 'com.android.application'

dependencies {
   api fileTree(include: ['*.jar'], dir: 'libs')
   api 'com.android.support:multidex:1.0.3'
   implementation(name: 'com.android.support.exifinterface-26.0.1', ext: 'aar')
   implementation(name: 'com.android.support.support-compat-26.0.1', ext: 'aar')
   implementation(name: 'com.android.support.support-core-ui-26.0.1', ext: 'aar')
   implementation(name: 'com.android.support.support-core-utils-26.0.1', ext: 'aar')
   implementation(name: 'com.android.support.support-fragment-26.0.1', ext: 'aar')
   implementation(name: 'com.android.support.support-media-compat-26.0.1', ext: 'aar')
   implementation(name: 'com.android.support.support-v4-26.0.1', ext: 'aar')
   implementation(name: 'com.google.android.gms.play-services-base-11.0.4', ext: 'aar')
   implementation(name: 'com.google.android.gms.play-services-basement-11.0.4', ext: 'aar')
   implementation(name: 'com.google.android.gms.play-services-games-11.0.4', ext: 'aar')
   implementation(name: 'com.google.android.gms.play-services-nearby-11.0.4', ext: 'aar')
   implementation(name: 'com.google.android.gms.play-services-tasks-11.0.4', ext: 'aar')
   implementation(name: 'play-services-ads-11.0.4', ext: 'aar')
   implementation(name: 'play-services-ads-lite-11.0.4', ext: 'aar')
   implementation(name: 'play-services-gass-11.0.4', ext: 'aar')
   implementation(name: 'play-services-location-11.0.4', ext: 'aar')
   api project(':adcolony')
   api project(':appodeal')
   api project(':common_lib')
   api project(':inmobi')
   api project(':native_plugins_lib')
   api project(':ogury')
   api project(':voxelbusters_utility_lib')
}

android {
   compileSdkVersion 28
   buildToolsVersion '28.0.3'

   defaultConfig {
      minSdkVersion 16
      targetSdkVersion 28
      targetSdkVersion 28
      versionCode 10
      versionName "10"
      applicationId '*MY APP ID HERE*'
      multiDexEnabled true
   }

   lintOptions {
      abortOnError false
      disable 'MissingTranslation'
      checkAllWarnings false
      checkReleaseBuilds false
      ignoreWarnings true       // false by default
      quiet true                // false by default
   }

   aaptOptions {
      noCompress '.unity3d', '.ress', '.resource', '.obb'
   }



    signingConfigs {
        release {
            storeFile file('*KEYSTORE PATH HERE*')
            storePassword '*PASSWORD*'
            keyAlias '*My KEY ALIAS*'
            keyPassword '*MY KEY PASSWORD*'
        }
    }
   buildTypes {
      debug {
         minifyEnabled false
         useProguard false
         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
         jniDebuggable true
         signingConfig signingConfigs.release
      }
      release {
         minifyEnabled false
         useProguard false
         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'

         signingConfig signingConfigs.release
      }
   }

}

如果您生成了 SignAPK 那么 -> .
对于发布版本: 在 Android 工作室终端

keytool -list -v -keystore "key_store_path" -alias "key_alias_name"

它会给你 SHA1, SHA256, MD5 。用这个改变你的 SHA1。

在gradle文件依赖中,添加

implementation 'com.google.code.gson:gson:2.8.5'

同时添加

mavenCentral()

在存储库中。

不确定为什么这在调试中不是问题,但在发布中却是问题。我猜其中一个广告库的代码使用带有发布标志的 GSON。