我正在使用bellow示例,但在添加库时遇到错误:
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
}
让我吼叫错误:
答案 0 :(得分:6)
错误是“找不到架构文件。请确保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
答案 1 :(得分:2)
您似乎正在使用旧版本的Apollo。这些警告已在最近的稳定版本中得到修复。
我建议你替换
classpath 'com.apollographql.android:gradle-plugin:0.1.0'
与
classpath 'com.apollographql.apollo:gradle-plugin:0.3.0'
并删除generateClasses = true
块以及converter-pojo
和apollo-api
依赖项。最新版本不再需要这些。
之后运行一个干净的构建。
答案 2 :(得分: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. Creating a personal access token for the command line