ApolloGraphql FileNotFoundException: source/apollo

2019-05-24 23:44发布

问题:

I am trying to add ApolloGraphql to my android project, but when i try to rebuild the project, i get :

org.gradle.api.UncheckedIOException: java.io.FileNotFoundException: /Users/mcebotari/Downloads/Projects/Barcloud/app/build/generated/source/apollo/generatedIR/snapshotDebug/src (Is a directory)

in build.gradle i have added the needed dependencies:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

apply plugin: 'com.apollographql.android'


android {
  compileSdkVersion 27
  defaultConfig {
    applicationId "barcloud.com"
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
  implementation fileTree(dir: 'libs', include: ['*.jar'])
  implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
  implementation 'com.android.support:appcompat-v7:27.1.1'
  implementation 'com.android.support:design:27.1.1'

  //Design
  implementation 'com.github.rasoulmiri:buttonloading:v1.0.8'

  //Vision Library
  implementation 'com.google.android.gms:play-services-vision:15.0.2'

  // RxJava
  implementation "io.reactivex.rxjava2:rxjava:2.1.16"
  implementation "io.reactivex:rxandroid:1.2.1"
  implementation "com.jakewharton.rxbinding:rxbinding:1.0.1"
  implementation "com.squareup.retrofit2:adapter-rxjava:2.3.0"
  implementation 'com.jakewharton.rxbinding:rxbinding-appcompat-v7:1.0.1'

  //RxPermissions
  implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.5@aar'

  //Retrofit
  implementation "com.squareup.retrofit2:retrofit:2.4.0"
  implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0"
  implementation "com.squareup.retrofit2:converter-gson:2.4.0"

  // rxandroid
  implementation "io.reactivex.rxjava2:rxandroid:2.0.1"

  // Dagger
  implementation "com.google.dagger:dagger:2.12"
  kapt "com.google.dagger:dagger-compiler:2.12"

  //GraphQL
  implementation 'com.apollographql.apollo:apollo-runtime:1.0.0-alpha'
  implementation 'com.apollographql.apollo:apollo-rx2-support:1.0.0-alpha'

  testImplementation 'junit:junit:4.12'
  androidTestImplementation 'com.android.support.test:runner:1.0.2'
  androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

and also the dependency:

classpath 'com.apollographql.apollo:apollo-gradle-plugin:1.0.0-alpha'

Trying to rebuild the project i get :

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:generateDebugApolloClasses'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
...
Caused by: org.gradle.api.UncheckedIOException: java.io.FileNotFoundException: /Users/mcebotari/Downloads/samples/Barcloud/app/build/generated/source/apollo/generatedIR/debug/src (Is a directory)
    at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:57)
...
Caused by: java.io.FileNotFoundException: /Users/mcebotari/Downloads/samples/Barcloud/app/build/generated/source/apollo/generatedIR/debug/src (Is a directory)
    at java.io.FileInputStream.open0(Native Method)

The graphql files are the ones from the official sample - GithuntFeedQuery.graphql and their schema.json, pasted in main folder.

Any ideas?

回答1:

There are two solutions which I came accross while researching this problem:

  1. Remove apollo from your project, (by editing your gradle files) clean your project, and add apollo again.

  2. Try changing the apollo version in your project gradle file, ie. mine worked with

classpath 'com.apollographql.apollo:gradle-plugin:0.3.1

and it was 0.3.2 originally.



回答2:

Had the same issue with prodRelease config, fixed by renaming prod flavor. In apps build.gradle I have:

buildTypes { 
  debug {...}
  release {...}
}
productFlavors {
  dev {...}
  stage {...}
  prod {...}
}

which gives me 6 buildVariants

devDebug
devRelease
stageDebug
stageRelease
prodDebug
prodRelease

top 5 were building without a problems locally and on CI, while prodRelease was giving me the same error as you described without any logical explanation. GraphQL files are the same for dev, stage and prod... I've tried to create specific folders for "prod" then for "prodRelease", checked their access rights - all the same for all variants, nothing helped. And prodDebug were building correctly all the time. Then I've renamed prod flavor(don't forget to rename graphql files folder accordingly) and it now works like a charm.