【问题标题】:Using the apollo graphql client for Android?使用适用于 Android 的 apollo graphql 客户端?
【发布时间】:2017-09-04 10:10:36
【问题描述】:

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

Using the apollo graphql client for Android

下面是我的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
}

告诉我以下错误:

【问题讨论】:

    标签: android graphql apollo android-studio-2.3 graphql-java


    【解决方案1】:

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

    使用apollo-codegen download-schema 命令创建此 JSON。这将 GraphQL 端点的 URL 作为参数,后跟 --output 和应该存储 JSON 的路径。 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
    

    【讨论】:

    • 我能做什么? 'apollo-codegen' 不是内部或外部命令、可运行程序或批处理文件。
    • @JoJoRoid: apollo-codegen 是一个节点包。运行 npm install -g apollo-codegen 命令。这将“全局”安装apollo-codegen,因此它可用于您希望使用 Apollo-Android 的任何 Android 项目。但请注意,使用 -g 开关进行全局安装可能需要您的开发计算机上的超级用户权限(例如,sudo)。
    • 告诉我这个错误:错误:任务':app:installApolloCodegen'的执行失败。 > Process 'command 'D:\AndroidStudioProject\TestApollo\app\.gradle\nodejs\node-v6.7.0-win-x64\node.exe'' 以非零退出值 -4048 结束
    • @JoJoRoid:对不起,我不知道那是什么意思。
    【解决方案2】:

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

    我建议你更换

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

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

    并摆脱 generateClasses = true 块以及 converter-pojoapollo-api 依赖项。最新版本不再需要这些。

    之后运行干净的构建。

    【讨论】:

      【解决方案3】:

      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. Creating a personal access token for the command line

      【讨论】:

        猜你喜欢
        • 2020-03-31
        • 2021-05-30
        • 2019-12-31
        • 2016-08-14
        • 2019-06-22
        • 2017-09-01
        • 2023-03-19
        • 2019-07-26
        • 1970-01-01
        相关资源
        最近更新 更多