3

我正在使用以下示例,但添加库时出现错误:

使用适用于 Android 的 apollo graphql 客户端

贝娄是我的build.gradle (project)

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {
        repositories {
            jcenter()
            maven { url "https://jitpack.io" }
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.1'
            classpath 'com.apollographql.android:gradle-plugin:0.1.0'
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

    allprojects {
        repositories {
            jcenter()
            mavenCentral()
        }
    }

    task clean(type: Delete) {
        delete rootProject.buildDir
    }

贝娄是我的build.gradle (Module)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.admin.apollotest"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    testCompile 'junit:junit:4.12'

    compile 'com.apollographql.android:api:0.1.0' // the apollo runtime classes needed by auto-generated code
    compile 'com.squareup.retrofit2:retrofit:2.1.0' // retrofit2
    compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0' // rxjava2 to use the Observables stuff
    compile 'com.apollographql.android:converter-pojo:0.1.0' // converts retrofit responses to pojos (ApolloConverterFactory)
}
apply plugin: 'com.apollographql.android'

apollo {
    // this tells the apollo compiler to generate actual static classes instead of just interfaces (more on that later)
    generateClasses = true
}

得到我下面的错误:

在此处输入图像描述

4

3 回答 3

10

错误是“找不到架构文件。请确保 sourceSet 目录中存在有效的 schema.json 文件”。

使用该apollo-codegen download-schema命令创建此 JSON。这将 GraphQL 端点的 URL 作为参数,后跟--outputJSON 应存储的路径。JSON 应该src/main/graphql/来自您的项目,并在其中进入代表您希望代码进入的 Java 包的子目录(例如,--output src/main/graphql/com/commonsware/graphql/trips/api/schema.json)。

所以,总的来说,你可能有:

apollo-codegen download-schema https://graphql-demo.commonsware.com/0.1/graphql --output src/main/graphql/com/commonsware/graphql/trips/api/schema.json
于 2017-04-09T11:16:16.047 回答
2

看来您使用的是旧版本的 Apollo。这些警告已在最近的稳定版本中得到修复。

建议你换

classpath 'com.apollographql.android:gradle-plugin:0.1.0'

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

并摆脱generateClasses = trueconverter-pojoapollo-api依赖关系。最新版本不再需要这些。

之后运行一个干净的构建。

于 2017-04-18T22:55:54.183 回答
0

Apollo CLI v2.17.2 (apollo-android v1.0.2 )的实现

特别是 GitHub API:

apollo client:download-schema /src/main/graphql/com/graphql/example/schema.json --endpoint https://api.github.com/graphql --header "Authorization: Bearer <github-token>"

GitHub。为命令行创建个人访问令牌

于 2019-08-07T12:58:59.360 回答