端点客户端库无法识别
Endpoint client library not recognized
不确定发生了什么,但是在移动到 gradle 3.0.0 rc2 之后,我的应用程序模块无法识别端点模块生成的任何客户端库。
构建可以完成 w/o 任何问题,只有一个例外...none 的新 API 被构建选中。
这是我的应用程序模块中 gradle 文件的依赖项部分:
dependencies {
// Gradle dependency check...must be run in the project directory
// ./gradlew -q dependencies app:dependencies --configuration compile
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(path: ':backend', configuration: 'android-endpoints')
更新:
我注意到 war/jar 文件在 backend/build/libs 中不断更新,zip 文件也在 backend/build/client-libs 中更新。
更新#2:
这发生在 Android Studio 3.0 中。
更新#3:
显然,这是 3.0 rc2 的一个已知错误,请参阅 here
更新#4
这是 Google 团队的建议,但我不知道如何让它发挥作用。有人吗?
//In library module:
dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
}
gradle 文件引用:
项目级别:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
// 2.0
classpath 'com.google.guava:guava:22.0'
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
端点(后端)级别:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
// V2: Add the new App Engine and Endpoints Frameworks plugin dependencies
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3'
}
}
repositories {
mavenCentral()
jcenter()
}
apply plugin: 'java'
apply plugin: 'war'
// V2: Apply new App Engine and Endpoints Framework server plugins
apply plugin: 'com.google.cloud.tools.appengine'
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
dependencies {
// V2: Endpoints Framework v2 migration
implementation 'com.google.endpoints:endpoints-framework:2.0.8'
testImplementation 'junit:junit:4.12'
testImplementation 'com.google.appengine:appengine-testing:1.9.59'
testImplementation 'com.google.appengine:appengine-api-stubs:1.9.59'
// 2.0
//implementation group: 'com.google.endpoints', name: 'endpoints-framework', version: '+'
implementation group: 'com.googlecode.junit-toolbox', name: 'junit-toolbox', version: '1.5'
implementation 'com.googlecode.objectify:objectify:5.1.21'
implementation 'org.json:json:20151123'
implementation 'javax.servlet:servlet-api:2.5'
implementation 'org.apache.httpcomponents:httpclient:4.5.2'
implementation 'com.ganyo:gcm-server:1.0.2'
implementation 'com.google.appengine.tools:appengine-gcs-client:0.4.4'
implementation 'com.google.apis:google-api-services-storage:v1-rev66-1.21.0'
implementation 'com.google.api-client:google-api-client:1.23.0'
implementation 'com.google.http-client:google-http-client-android:1.23.0'
// I think this can be deleted
//implementation 'commons-fileupload:commons-fileupload:1.3.1'
}
appengine {
// All commented out due to v2
//downloadSdk = true
/*appcfg {
oauth2 = true
}*/
/*endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
googleClientVersion = '1.23.0'
}*/
//httpAddress = "0.0.0.0"
}
// 2.0 - optional
endpointsServer {
// Endpoints Framework Plugin server-side configuration
hostname = "mickey-mouse-pooh.appspot.com"
}
应用级别:
apply plugin: 'com.android.application'
// V2: Apply the new Endpoints Framework client plugin
apply plugin: 'com.google.cloud.tools.endpoints-framework-client'
buildscript {
repositories {
jcenter()
}
dependencies {
// V2: Add the new Endpoints Framework plugin dependencies
classpath 'com.google.cloud.tools:endpoints-framework-gradle-
plugin:1.0.2'
}
}
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.inneraries.projectboon"
minSdkVersion 20 // before to update
targetSdkVersion 26
android.compileOptions.sourceCompatibility 1.8
android.compileOptions.targetCompatibility 1.8
versionCode 112
versionName 'Phoenix'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
// Gradle dependency check...must be run in the project directory
// ./gradlew -q dependencies app:dependencies --configuration compile
implementation fileTree(include: ['*.jar'], dir: 'libs')
// V2
endpointsServer project(path: ':backend', configuration: 'endpoints')
// the "force" element is in place to avoid the conflict from the Facebook SDK 4.36.0 which is
// using 25.3.1 Android SDK
api('com.android.support:appcompat-v7:26.1.0') {
force = true
}
api('com.android.support:design:26.1.0') {
force = true
}
// For enabling Google app invite
api 'com.google.firebase:firebase-invites:11.4.2'
api 'com.google.android.gms:play-services-plus:11.4.2'
api 'com.google.android.gms:play-services-auth:11.4.2'
api 'com.google.android.gms:play-services-identity:11.4.2'
api 'com.google.android.gms:play-services-location:11.4.2'
api 'com.google.android.gms:play-services-gcm:11.4.2'
api 'com.facebook.android:facebook-android-sdk:4.27.0'
api 'com.google.api-client:google-api-client:1.23.0'
api 'com.google.http-client:google-http-client-android:1.23.0'
}
// this is to avoid this error
// Warning:Conflict with dependency 'com.google.code.findbugs:jsr305'.
// Resolved versions for app (1.3.9) and test app (2.0.1) differ.
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
这是 Google 截至 2017 年 11 月 1 日的展位:Upgrade the framework to v2。
他们还提供了一些解决方法(您的经理可能不喜欢这样):
- Build the client library manually and copy it over. [Use gradle task : appengineEndpointsGetClientLibs]
Export a pre-built jar and copy it over. [Use gradle task : appengineEndpointsExportClientLibs] NOTE : 2 and 3 will require you to
add the google-api-client-lib dependency directly on the android app
Try to use the new plugins that use a different mechanism, while it does automatically add source to your project, this does NOT integrate
with Android Studio's UI - so you will have to use gradle/command-line
tooling directly for running and deploying:
https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/blob/master/ANDROID_README.md
我已经在问题描述中提供了我的 gradle 文件,以供您参考。
我在过去 10 天里调查了这个问题,这是我所了解的。 Google 关于端点开发的哲学,自第一次引入以来就集成在 Android Studio 中,现在已经发生了变化。事实上,AndroidStudio 3 将不再提供对端点的原生支持(事实上,您不能再添加端点模块)。
基本上,他们试图将后端开发(这对所有平台都是通用的)与客户端开发分开。因此,他们会鼓励您在 IntelliJ 上开发后端,然后将生成的库导入您的 'lib' 文件夹(现在是项目创建时的默认文件夹)。他们还为 IntelliJ 提供了专用端点部署工具(参见 https://cloud.google.com/tools/intellij/docs/)。
不确定发生了什么,但是在移动到 gradle 3.0.0 rc2 之后,我的应用程序模块无法识别端点模块生成的任何客户端库。
构建可以完成 w/o 任何问题,只有一个例外...none 的新 API 被构建选中。
这是我的应用程序模块中 gradle 文件的依赖项部分:
dependencies {
// Gradle dependency check...must be run in the project directory
// ./gradlew -q dependencies app:dependencies --configuration compile
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(path: ':backend', configuration: 'android-endpoints')
更新:
我注意到 war/jar 文件在 backend/build/libs 中不断更新,zip 文件也在 backend/build/client-libs 中更新。
更新#2:
这发生在 Android Studio 3.0 中。
更新#3: 显然,这是 3.0 rc2 的一个已知错误,请参阅 here
更新#4 这是 Google 团队的建议,但我不知道如何让它发挥作用。有人吗?
//In library module:
dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
}
gradle 文件引用:
项目级别:
buildscript {
repositories {
jcenter()
google()
}
dependencies {
// 2.0
classpath 'com.google.guava:guava:22.0'
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
端点(后端)级别:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
// V2: Add the new App Engine and Endpoints Frameworks plugin dependencies
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3'
}
}
repositories {
mavenCentral()
jcenter()
}
apply plugin: 'java'
apply plugin: 'war'
// V2: Apply new App Engine and Endpoints Framework server plugins
apply plugin: 'com.google.cloud.tools.appengine'
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
dependencies {
// V2: Endpoints Framework v2 migration
implementation 'com.google.endpoints:endpoints-framework:2.0.8'
testImplementation 'junit:junit:4.12'
testImplementation 'com.google.appengine:appengine-testing:1.9.59'
testImplementation 'com.google.appengine:appengine-api-stubs:1.9.59'
// 2.0
//implementation group: 'com.google.endpoints', name: 'endpoints-framework', version: '+'
implementation group: 'com.googlecode.junit-toolbox', name: 'junit-toolbox', version: '1.5'
implementation 'com.googlecode.objectify:objectify:5.1.21'
implementation 'org.json:json:20151123'
implementation 'javax.servlet:servlet-api:2.5'
implementation 'org.apache.httpcomponents:httpclient:4.5.2'
implementation 'com.ganyo:gcm-server:1.0.2'
implementation 'com.google.appengine.tools:appengine-gcs-client:0.4.4'
implementation 'com.google.apis:google-api-services-storage:v1-rev66-1.21.0'
implementation 'com.google.api-client:google-api-client:1.23.0'
implementation 'com.google.http-client:google-http-client-android:1.23.0'
// I think this can be deleted
//implementation 'commons-fileupload:commons-fileupload:1.3.1'
}
appengine {
// All commented out due to v2
//downloadSdk = true
/*appcfg {
oauth2 = true
}*/
/*endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
googleClientVersion = '1.23.0'
}*/
//httpAddress = "0.0.0.0"
}
// 2.0 - optional
endpointsServer {
// Endpoints Framework Plugin server-side configuration
hostname = "mickey-mouse-pooh.appspot.com"
}
应用级别:
apply plugin: 'com.android.application'
// V2: Apply the new Endpoints Framework client plugin
apply plugin: 'com.google.cloud.tools.endpoints-framework-client'
buildscript {
repositories {
jcenter()
}
dependencies {
// V2: Add the new Endpoints Framework plugin dependencies
classpath 'com.google.cloud.tools:endpoints-framework-gradle-
plugin:1.0.2'
}
}
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.inneraries.projectboon"
minSdkVersion 20 // before to update
targetSdkVersion 26
android.compileOptions.sourceCompatibility 1.8
android.compileOptions.targetCompatibility 1.8
versionCode 112
versionName 'Phoenix'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
// Gradle dependency check...must be run in the project directory
// ./gradlew -q dependencies app:dependencies --configuration compile
implementation fileTree(include: ['*.jar'], dir: 'libs')
// V2
endpointsServer project(path: ':backend', configuration: 'endpoints')
// the "force" element is in place to avoid the conflict from the Facebook SDK 4.36.0 which is
// using 25.3.1 Android SDK
api('com.android.support:appcompat-v7:26.1.0') {
force = true
}
api('com.android.support:design:26.1.0') {
force = true
}
// For enabling Google app invite
api 'com.google.firebase:firebase-invites:11.4.2'
api 'com.google.android.gms:play-services-plus:11.4.2'
api 'com.google.android.gms:play-services-auth:11.4.2'
api 'com.google.android.gms:play-services-identity:11.4.2'
api 'com.google.android.gms:play-services-location:11.4.2'
api 'com.google.android.gms:play-services-gcm:11.4.2'
api 'com.facebook.android:facebook-android-sdk:4.27.0'
api 'com.google.api-client:google-api-client:1.23.0'
api 'com.google.http-client:google-http-client-android:1.23.0'
}
// this is to avoid this error
// Warning:Conflict with dependency 'com.google.code.findbugs:jsr305'.
// Resolved versions for app (1.3.9) and test app (2.0.1) differ.
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
这是 Google 截至 2017 年 11 月 1 日的展位:Upgrade the framework to v2。
他们还提供了一些解决方法(您的经理可能不喜欢这样):
- Build the client library manually and copy it over. [Use gradle task : appengineEndpointsGetClientLibs]
Export a pre-built jar and copy it over. [Use gradle task : appengineEndpointsExportClientLibs] NOTE : 2 and 3 will require you to add the google-api-client-lib dependency directly on the android app
Try to use the new plugins that use a different mechanism, while it does automatically add source to your project, this does NOT integrate with Android Studio's UI - so you will have to use gradle/command-line tooling directly for running and deploying: https://github.com/GoogleCloudPlatform/endpoints-framework-gradle-plugin/blob/master/ANDROID_README.md
我已经在问题描述中提供了我的 gradle 文件,以供您参考。
我在过去 10 天里调查了这个问题,这是我所了解的。 Google 关于端点开发的哲学,自第一次引入以来就集成在 Android Studio 中,现在已经发生了变化。事实上,AndroidStudio 3 将不再提供对端点的原生支持(事实上,您不能再添加端点模块)。 基本上,他们试图将后端开发(这对所有平台都是通用的)与客户端开发分开。因此,他们会鼓励您在 IntelliJ 上开发后端,然后将生成的库导入您的 'lib' 文件夹(现在是项目创建时的默认文件夹)。他们还为 IntelliJ 提供了专用端点部署工具(参见 https://cloud.google.com/tools/intellij/docs/)。