2017-12-27 4 views
3

當我嘗試在物理設備上運行我的應用程序時,出現錯誤路徑可能不爲空或空字符串。 path ='null'在項目的構建階段,但構建運行很好,如果我嘗試在模擬器上運行應用程序。用minifyEnabled = true在設備上運行的路徑null

我做了一些實驗,我發現這種行爲是由於minifyEnabled = true,但我還沒有找到一種方法來了解哪些路徑爲空以及爲什麼。

有沒有人已經解決了這樣的問題?

這是我的build.gradle文件

buildscript { 
    repositories { 
     maven { url 'https://maven.fabric.io/public' } 
    } 

    dependencies { 
     classpath 'io.fabric.tools:gradle:1.+' 
    } 
} 

repositories { 
    maven { url 'https://maven.fabric.io/public' } 
} 

import com.android.build.OutputFile; 

apply plugin: 'com.android.application' 
apply plugin: 'realm-android' 
apply plugin: 'io.fabric' 
apply plugin: 'let' 
apply plugin: "org.sonarqube" 

Properties localProperties = new Properties() 
try { 
    localProperties.load(project.rootProject.file('local.properties').newDataInputStream()) 
} catch (Exception e) { 
    localProperties = null 
} 

def versionMajor = 0 // Max one digit 
def versionMinor = 2 // Max one digit 
def versionPatch = 6 // Max one digit 
def versionBuild = 6 // Max two digits: bump for dogfood builds, public betas, etc. 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.3" 
    defaultConfig { 
     minSdkVersion 16 
     targetSdkVersion 25 
     renderscriptTargetApi 17 
     renderscriptSupportModeEnabled true 
     versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild 
     versionName "${versionMajor}.${versionMinor}.${versionPatch}" 
     multiDexEnabled true 
     dataBinding { 
      enabled = true 
     } 
     vectorDrawables.useSupportLibrary = true 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     testInstrumentationRunnerArguments disableAnalytics: 'true' // Analytics opt-out. 
    } 
    productFlavors { 
     envProd { 
      applicationId "xxx" 
      buildConfigField("String", "API_KEY", "xxx") 

      crashlytics { 
       enableNdk true 
       androidNdkOut 'build/intermediates/transforms/mergeJniLibs/envProd/release/folders/2000/1f/main/lib/' 
       androidNdkLibsOut 'build/intermediates/transforms/stripDebugSymbol/envProd/release/folders/2000/1f/main/lib' 
      } 

     } 
     envTest { 
      applicationId "xxx" 
      buildConfigField("String", "API_KEY", "xxx") 

      crashlytics { 
       enableNdk true 
       androidNdkOut 'build/intermediates/transforms/mergeJniLibs/envTest/release/folders/2000/1f/main/lib/' 
       androidNdkLibsOut 'build/intermediates/transforms/stripDebugSymbol/envTest/release/folders/2000/1f/main/lib' 
      } 

     } 
    } 
    signingConfigs { 
     release { 
      if (localProperties != null) { 
       storeFile file(localProperties['store.file']) 
       storePassword localProperties['store.password'] 
       keyAlias localProperties['key.alias'] 
       keyPassword localProperties['key.password'] 
      } 
     } 
    } 
    buildTypes { 
     all { 
      buildConfigField "java.util.Date", "BUILD_DATE", "new java.util.Date(" + System.currentTimeMillis() + "L)" 
     } 
     debug { 
      applicationIdSuffix ".debug" 
      ext.enableCrashlytics = false // Disable fabric build ID generation for debug builds 
      ndk { 
       abiFilters = [] 
       abiFilters.addAll(['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64']) 
      } 
     } 
     release { 
      signingConfig signingConfigs.release 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 
        'proguard-crashlytics.pro', 
        'proguard-rules.pro', 
        'proguard-support-v7-appcompat.pro', 
        'proguard-google-play-services.pro', 
        'proguard-eventbus.pro', 
        'proguard-let.pro', 
        'proguard-gson.pro', 
        'proguard-guava.pro', 
        'proguard-aws.pro', 
        'proguard-calligraphy.pro' 
      ndk { 
       abiFilters = [] 
       abiFilters.addAll(['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64']) 
      } 
     } 
    } 
    splits { 
     abi { 
      enable true 
      reset() 
      include 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' 
      universalApk false 
     } 
    } 
    packagingOptions { 
     pickFirst 'lib/armeabi-v7a/libopencv_imgproc.so' 
     pickFirst 'lib/armeabi-v7a/libopencv_core.so' 
     pickFirst 'lib/arm64-v8a/libopencv_imgproc.so' 
     pickFirst 'lib/arm64-v8a/libopencv_core.so' 
     pickFirst 'lib/x86/libopencv_imgproc.so' 
     pickFirst 'lib/x86/libopencv_core.so' 
     pickFirst 'lib/x86_64/libopencv_imgproc.so' 
     pickFirst 'lib/x86_64/libopencv_core.so' 
    } 
    dataBinding { 
     enabled = true 
    } 
    testOptions.unitTests.all { 
     testLogging { // Always show the result of every unit test, even if it passes. 
      events 'passed', 'skipped', 'failed', 'standardOut', 'standardError' 
     } 
    } 
} 

dependencies { 
    compile project('xxx') 
    compile project('xxx') 
    compile project('xxx') 
    envTestCompile project('xxx') 
    envProdCompile project('xxx') 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile('com.crashlytics.sdk.android:crashlytics:[email protected]') { 
     transitive = true; 
    } 
    compile('com.crashlytics.sdk.android:crashlytics-ndk:[email protected]') { 
     transitive = true; 
    } 
    // Testing 
    androidTestCompile('com.android.support.test:runner:0.5') { 
     exclude module: 'support-annotations' 
    } 
    // Set this dependency to use JUnit 4 rules 
    androidTestCompile('com.android.support.test:rules:0.5') { 
     exclude module: 'support-annotations' 
    } 
    // Set this dependency to build and run Espresso tests 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') { 
     exclude module: 'support-annotations' 
    } 
    // Set this dependency to build and run UI Automator tests 
    androidTestCompile('com.android.support.test.uiautomator:uiautomator-v18:2.1.2') { 
     exclude module: 'support-annotations' 
    } 
    compile 'com.android.support:multidex:1.0.1' 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.android.support:support-v4:25.3.1' 
    compile 'com.google.android.gms:play-services-vision:11.0.4' 
    compile 'com.google.android.gms:play-services-location:11.0.4' 
    compile 'com.google.android.gms:play-services-safetynet:11.0.4' 
    compile 'com.android.support:cardview-v7:25.3.1' 
    compile 'com.github.bumptech.glide:glide:3.8.0' 
    compile 'jp.wasabeef:glide-transformations:2.0.2' 
    compile 'com.google.guava:guava:19.0' 
    compile 'com.googlecode.libphonenumber:libphonenumber:8.3.1' 
    compile 'uk.co.chrisjenx:calligraphy:2.2.0' 
    compile 'org.greenrobot:eventbus:3.0.0' 
    compile 'com.github.paolorotolo:appintro:4.1.0' 
    compile 'com.facebook.rebound:rebound:0.3.8' 
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4' 
    compile 'com.android.support:recyclerview-v7:25.3.1' 
    compile 'com.android.support:design:25.3.1' 
    compile 'com.amazonaws:aws-android-sdk-core:2.6.11' 
    compile 'com.amazonaws:aws-android-sdk-s3:2.6.11' 
    testCompile 'junit:junit:4.12' 
    testCompile 'org.hamcrest:hamcrest-core:1.3' 
    androidTestCompile 'org.mockito:mockito-core:1.10.19' 
    androidTestCompile 'com.crittercism.dexmaker:dexmaker:1.4' 
    androidTestCompile 'com.crittercism.dexmaker:dexmaker-dx:1.4' 
    androidTestCompile 'com.crittercism.dexmaker:dexmaker-mockito:1.4' 
} 


// map for the version code, max 2 digits 
project.ext.abiCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9] 

android.applicationVariants.all { variant -> 
    // assign different version code for each output 
    variant.outputs.each { output -> 
     output.versionCodeOverride = 
       (variant.mergedFlavor.getMinSdkVersion().getApiLevel() * 10000000 
         + project.ext.abiCodes.get(output.getFilter(OutputFile.ABI)) * 100000 
         + variant.mergedFlavor.versionCode) 
    } 
} 

這是錯誤的完整堆棧跟蹤:

java.lang.IllegalArgumentException: path may not be null or empty string. path='null' 
    at org.gradle.api.internal.file.BaseDirFileResolver.doResolve(BaseDirFileResolver.java:72) 
    at org.gradle.api.internal.file.AbstractFileResolver.resolve(AbstractFileResolver.java:79) 
    at org.gradle.api.internal.file.AbstractFileResolver.resolve(AbstractFileResolver.java:61) 
    at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext$FileCollectionConverter.convertInto(DefaultFileCollectionResolveContext.java:173) 
    at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.doResolve(DefaultFileCollectionResolveContext.java:134) 
    at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.resolveAsFileCollections(DefaultFileCollectionResolveContext.java:92) 
    at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext$FileCollectionConverter.convertInto(DefaultFileCollectionResolveContext.java:157) 
    at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.doResolve(DefaultFileCollectionResolveContext.java:109) 
    at org.gradle.api.internal.file.collections.DefaultFileCollectionResolveContext.resolveAsFileCollections(DefaultFileCollectionResolveContext.java:92) 
    at org.gradle.api.internal.file.CompositeFileCollection.getSourceCollections(CompositeFileCollection.java:172) 
    at org.gradle.api.internal.file.CompositeFileCollection.visitRootElements(CompositeFileCollection.java:184) 
    at org.gradle.api.internal.changedetection.state.AbstractFileCollectionSnapshotter.snapshot(AbstractFileCollectionSnapshotter.java:78) 
    at org.gradle.api.internal.changedetection.rules.AbstractNamedFileSnapshotTaskStateChanges.buildSnapshots(AbstractNamedFileSnapshotTaskStateChanges.java:87) 
    at org.gradle.api.internal.changedetection.rules.AbstractNamedFileSnapshotTaskStateChanges.<init>(AbstractNamedFileSnapshotTaskStateChanges.java:54) 
    at org.gradle.api.internal.changedetection.rules.InputFilesTaskStateChanges.<init>(InputFilesTaskStateChanges.java:28) 
    at org.gradle.api.internal.changedetection.rules.TaskUpToDateState.<init>(TaskUpToDateState.java:55) 
    at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.getStates(DefaultTaskArtifactStateRepository.java:164) 
    at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.isUpToDate(DefaultTaskArtifactStateRepository.java:79) 
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:51) 
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58) 
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88) 
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46) 
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51) 
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54) 
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) 
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34) 
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236) 
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228) 
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169) 
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106) 
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61) 
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228) 
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215) 
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77) 
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58) 
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32) 
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113) 
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37) 
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37) 
    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23) 
    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43) 
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) 
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37) 
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30) 
    at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:196) 
    at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:193) 
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169) 
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106) 
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56) 
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193) 
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119) 
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102) 
    at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71) 
    at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:50) 
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35) 
    at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner$1.execute(RunAsBuildOperationBuildActionRunner.java:43) 
    at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner$1.execute(RunAsBuildOperationBuildActionRunner.java:40) 
    at org.gradle.internal.Transformers$4.transform(Transformers.java:169) 
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106) 
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56) 
    at org.gradle.tooling.internal.provider.runner.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:40) 
    at org.gradle.tooling.internal.provider.runner.SubscribableBuildActionRunner.run(SubscribableBuildActionRunner.java:75) 
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35) 
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41) 
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26) 
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75) 
    at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49) 
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44) 
    at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29) 
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67) 
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36) 
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47) 
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26) 
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 
    at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34) 
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74) 
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72) 
    at org.gradle.util.Swapper.swap(Swapper.java:38) 
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72) 
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 
    at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55) 
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60) 
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36) 
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72) 
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36) 
    at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120) 
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50) 
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297) 
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54) 
    at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40) 
+0

哪一行會導致錯誤? –

+0

如果我註釋掉「minifyEnabled true」這一行,則在智能手機上運行時,構建也會成功完成 – TheOni

+0

這不能回答我的問題。 –

回答

-1

嘗試刪除這個:

Properties localProperties = new Properties() 
try { 
    localProperties.load(project.rootProject.file('local.properties').newDataInputStream()) 
} catch (Exception e) { 
    localProperties = null 
} 

這:

signingConfigs { 
    release { 
     if (localProperties != null) { 
      storeFile file(localProperties['store.file']) 
      storePassword localProperties['store.password'] 
      keyAlias localProperties['key.alias'] 
      keyPassword localProperties['key.password'] 
     } 
    } 
} 

並嘗試手動簽署構建

+0

@TheOni你試過嗎?我回答這個是因爲我只能找到與路徑相關的代碼段。 – anujtayal

+0

這部分代碼工作正常,如果我在模擬器中運行它的構建完成沒有任何錯誤。如果我刪除minifyEnabled,它也可以正常工作,如果我在物理設備上運行它 – TheOni