已签名的APK无法正常运行,但调试版本可以正常运行

时间:2018-11-19 02:21:31

标签: android android-studio unity3d gradle apk

我将Unity游戏导出到android studio,因为我使用了太多的DEX文件(由于广告网络库)。我可以毫无问题地构建和运行调试版本。我可以构建一个经过签名的发行版本,并将其上传到Playstore,但是游戏在启动时崩溃。日志说:

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

At [java code from an ad network library]

我没有使用proguard,调试和发行版之间的设置相同,除了在发行版中将debuggable和Jni debuggable设置为false之外。依赖项的范围是“全部实现”(也尝试过API,没有任何区别)。

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

编辑:

根据要求分级如下:

// 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
      }
   }

}

2 个答案:

答案 0 :(得分:0)

如果您生成了SignAPK,则->。
对于发布版本: 在Android Studio终端中

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

它将为您提供SHA1,SHA256,MD5。以此更改您的SHA1。

答案 1 :(得分:0)

在gradle文件依赖项中,添加

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

也添加

mavenCentral()

在存储库中。

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

相关问题