从 v1 到 2 的 Apollo GraphQL 迁移
Posted
技术标签:
【中文标题】从 v1 到 2 的 Apollo GraphQL 迁移【英文标题】:Apollo GraphQL migration from v1 - 2 【发布时间】:2021-05-29 06:06:06 【问题描述】:我正在尝试从 v1.3.3 -> 2.5.4 更新我的 Apollo 实现。我遵循了超级简单的迁移指南,但每当我这样做时,都会出现以下错误。
Execution failed for task ':app:dataBindingMergeDependencyArtifactsOuterspatialDebug'.
> Could not resolve all files for configuration ':app:outerspatialDebugCompileClasspath'.
> Could not resolve com.apollographql.apollo:apollo-normalized-cache-sqlite:2.5.4.
Required by:
project :app
> The consumer was configured to find an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'default' with value 'outerspatial'. However we cannot choose between the following variants of com.apollographql.apollo:apollo-normalized-cache-sqlite:2.5.4:
- android-debugApiElements
- android-debugRuntimeElements
- jvm-api
- jvm-runtime
All of them match the consumer attributes:
- Variant 'android-debugApiElements' capability com.apollographql.apollo:apollo-normalized-cache-sqlite:2.5.4 declares an API of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
- Unmatched attributes:
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
- Provides attribute 'com.android.build.gradle.internal.dependency.AndroidTypeAttr' with value 'Aar' but the consumer didn't ask for it
- Doesn't say anything about default (required 'outerspatial')
- Provides release status but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Variant 'android-debugRuntimeElements' capability com.apollographql.apollo:apollo-normalized-cache-sqlite:2.5.4 declares a runtime of a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug':
- Unmatched attributes:
- Provides attribute 'com.android.build.api.attributes.VariantAttr' with value 'debug' but the consumer didn't ask for it
- Provides attribute 'com.android.build.gradle.internal.dependency.AndroidTypeAttr' with value 'Aar' but the consumer didn't ask for it
- Doesn't say anything about default (required 'outerspatial')
- Provides release status but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but the consumer didn't ask for it
- Variant 'jvm-api' capability com.apollographql.apollo:apollo-normalized-cache-sqlite:2.5.4 declares an API of a component:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Doesn't say anything about default (required 'outerspatial')
- Provides its elements packaged as a jar but the consumer didn't ask for it
- Provides release status but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but the consumer didn't ask for it
- Variant 'jvm-runtime' capability com.apollographql.apollo:apollo-normalized-cache-sqlite:2.5.4 declares a runtime of a component:
- Unmatched attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Doesn't say anything about default (required 'outerspatial')
- Provides its elements packaged as a jar but the consumer didn't ask for it
- Provides release status but the consumer didn't ask for it
- Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but the consumer didn't ask for it
The following variants were also considered but didn't match the requested attributes:
- Variant 'android-releaseApiElements' capability com.apollographql.apollo:apollo-normalized-cache-sqlite:2.5.4 declares an API of a component:
- Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
- Other compatible attribute:
- Doesn't say anything about default (required 'outerspatial')
- Variant 'android-releaseRuntimeElements' capability com.apollographql.apollo:apollo-normalized-cache-sqlite:2.5.4 declares a runtime of a component:
- Incompatible because this component declares a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'release' and the consumer needed a component, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug'
- Other compatible attribute:
- Doesn't say anything about default (required 'outerspatial')
- Variant 'ios-api' capability com.apollographql.apollo:apollo-normalized-cache-sqlite:2.5.4:
- Incompatible because this component declares a usage of 'kotlin-api' of a component and the consumer needed an API of a component
- Other compatible attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Doesn't say anything about default (required 'outerspatial')
- Variant 'iosSim-api' capability com.apollographql.apollo:apollo-normalized-cache-sqlite:2.5.4:
- Incompatible because this component declares a usage of 'kotlin-api' of a component and the consumer needed an API of a component
- Other compatible attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Doesn't say anything about default (required 'outerspatial')
- Variant 'metadata-api' capability com.apollographql.apollo:apollo-normalized-cache-sqlite:2.5.4:
- Incompatible because this component declares a usage of 'kotlin-api' of a component and the consumer needed an API of a component
- Other compatible attributes:
- Doesn't say anything about com.android.build.api.attributes.BuildTypeAttr (required 'debug')
- Doesn't say anything about default (required 'outerspatial')
似乎与某些 android/java 文件存在某种冲突。我已经多次阅读简短的设置文档,看不出我的实现与示例有什么不同。有人知道吗?
我的应用级依赖如下:
dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
// implementation 'com.android.support:support-compat:28.0.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.squareup.okhttp3:okhttp:4.6.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
implementation 'com.github.bumptech.glide:glide:4.10.0'
implementation 'androidx.work:work-runtime:2.5.0'
// apollo
implementation 'com.apollographql.apollo:apollo-android-support:2.5.4'
implementation 'com.apollographql.apollo:apollo-gradle-plugin:2.5.4'
implementation 'com.apollographql.apollo:apollo-http-cache:2.5.4'
implementation 'com.apollographql.apollo:apollo-runtime:2.5.4'
implementation 'ca.mimic:oauth2library:2.4.2'
implementation('com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.0')
exclude group: 'group_name', module: 'module_name'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.9.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation platform('com.google.firebase:firebase-bom:26.1.0')
releaseImplementation 'com.google.firebase:firebase-analytics'
releaseImplementation 'com.google.firebase:firebase-crashlytics'
releaseImplementation 'com.google.firebase:firebase-appindexing'
releaseImplementation 'com.google.firebase:firebase-perf'
implementation 'io.branch.sdk.android:library:5.0.1'
implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
implementation 'com.segment.analytics.android:analytics:4.9.0'
implementation 'com.google.android.play:core:1.9.1'
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
implementation "androidx.room:room-runtime:2.2.6"
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
implementation "com.leinardi.android:speed-dial:3.1.1"
implementation 'com.google.android.gms:play-services-location:18.0.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
compileOnly 'org.jetbrains:annotations:13.0'
testCompileOnly 'org.jetbrains:annotations:13.0'
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.5'
项目级别:
buildscript
repositories
jcenter()
maven url 'https://maven.fabric.io/public'
mavenCentral()
google()
dependencies
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.apollographql.apollo:apollo-gradle-plugin:2.5.4'
classpath 'com.google.gms:google-services:4.3.4'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.4.1'
classpath 'com.google.firebase:perf-plugin:1.3.4'
【问题讨论】:
【参考方案1】:我遇到了一个非常相似的问题,仍在寻找最佳解决方案。
现在对我有用的是降级 类路径“com.android.tools.build:gradle:4.1.2”到类路径“com.android.tools.build:gradle:4.0.2”。一旦我这样做了,项目就开始构建了。
另一种方法是,如果我保留 'v4.1.2' 并在我添加的应用程序级 gradle 文件中:
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
matchingFallbacks = ["release"]
debug
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
matchingFallbacks = ["release"]
【讨论】:
以上是关于从 v1 到 2 的 Apollo GraphQL 迁移的主要内容,如果未能解决你的问题,请参考以下文章
如何将数据从反应组件传递到 Apollo graphql 查询?
带有 Vertx 订阅的 Apollo GraphQL 失败