我将Android应用和后端从Google Cloud EndPoints 1.0迁移到2.0。来自Android应用程序的Endpoint调用现在失败了404。
我确实将web.xml配置更改为指向/ _ah / api而不是/ _ah / spi。但是,日志仍会报告对spi而不是api的调用。
当我使用API资源管理器时,Web UI会报告对/ _ah / api进行的调用,但是appengine日志会将它们报告为/ _ah / spi。两者都报告404错误。
我花了几个小时阅读网上的所有内容并尝试。没运气。前段时间我成功迁移了另一个应用程序和后端。我比较了两者,看不出有什么不同。
项目build.gradle:
buildscript {
repositories {
jcenter()
google()
mavenCentral()
maven {
url "central.maven.org"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.google.gms:google-services:3.1.2'
classpath 'com.google.guava:guava:23.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.cloud.tools.endpoints-framework-client'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
}
}
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.playposse.peertopeeroxygen.android"
minSdkVersion 21
targetSdkVersion 27
versionCode 23
versionName "23.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
jumboMode true
}
}
repositories {
mavenCentral()
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files('libs/YouTubeAndroidPlayerApi.jar')
endpointsServer project(path: ':backend', configuration: 'endpoints')
// Set this dependency to use JUnit 4 rules
// Set this dependency to build and run Espresso tests
// Set this dependency to build and run UI Automator tests
androidTestImplementation group: 'com.restfb', name: 'restfb', version: '1.43.0'
// Needed to resolve conflict
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.android.support:customtabs:27.1.0'
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:percent:27.1.0'
implementation 'com.google.zxing:core:3.3.0'
implementation 'com.google.zxing:android-core:3.3.0'
implementation 'com.google.android.gms:play-services-analytics:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.google.android.gms:play-services-vision:12.0.1'
implementation 'com.google.android.gms:play-services-drive:12.0.1'
implementation 'com.google.firebase:firebase-core:12.0.1'
implementation 'com.google.firebase:firebase-messaging:12.0.1'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.android.support:support-annotations:27.1.0'
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'com.google.api-client:google-api-client:+'
implementation 'com.google.http-client:google-http-client-android:1.23.0'
testImplementation 'junit:junit:4.12'
testImplementation 'org.powermock:powermock-api-mockito:1.6.4'
testImplementation 'org.powermock:powermock-module-junit4-rule-agent:1.6.4'
testImplementation 'org.powermock:powermock-module-junit4-rule:1.6.4'
testImplementation 'org.powermock:powermock-module-junit4:1.6.4'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test:rules:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-web:3.0.1'
androidTestImplementation 'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
androidTestImplementation 'com.android.support:support-annotations:27.1.0'
androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.2'
}
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
apply plugin: 'com.google.gms.google-services'
后端build.gradle:
// If you would like more information on the gradle-appengine-plugin please refer to the github page
// https://github.com/GoogleCloudPlatform/gradle-appengine-plugin
buildscript {
repositories {
jcenter()
google()
mavenCentral()
}
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 {
jcenter()
mavenCentral()
google()
}
apply plugin: 'java'
apply plugin: 'war'
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 {
implementation 'com.google.endpoints:endpoints-framework:2.0.9'
implementation 'javax.servlet:servlet-api:2.5'
implementation 'com.google.guava:guava:24.1-jre'
implementation 'com.googlecode.objectify:objectify:5.1.17'
implementation group: 'com.restfb', name: 'restfb', version: '1.43.0'
implementation group: 'org.json', name: 'json', version: '20160810'
implementation 'com.google.http-client:google-http-client:1.23.0'
}
// V2: Define deployment configuration using the new App Engine plugin
// with the appengine closure
appengine { // App Engine tasks configuration
deploy { // deploy configuration
// The following is used for acceptance tests and
// is not required for a migration.
project = findProperty("appengine.deploy.project")
version = findProperty("appengine.deploy.version")
def promoteProp = findProperty("appengine.deploy.promote")
if (promoteProp != null) {
promote = new Boolean(promoteProp)
}
}
}
应用服务引擎-web.xml中
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>peertopeeroxygen</application>
<version>1</version>
<runtime>java8</runtime>
<threadsafe>true</threadsafe>
<url-stream-handler>urlfetch</url-stream-handler>
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>
</appengine-web-app>
的web.xml
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>EndpointsServlet</servlet-name>
<servlet-class>com.google.api.server.spi.EndpointsServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.playposse.peertopeeroxygen.backend.PeerToPeerOxygenEndPoint</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>EndpointsServlet</servlet-name>
<url-pattern>/_ah/api/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<filter>
<filter-name>ObjectifyFilter</filter-name>
<filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ObjectifyFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>com.playposse.peertopeeroxygen.backend.util.ObjectifyRegistrationServletContextListener</listener-class>
</listener>
</web-app>