在android studio上从java 7迁移到8的GAE

时间:2018-01-03 07:29:01

标签: android-studio google-app-engine

我尝试使用下面的迁移指南将Google App Engine迁移到java8。

https://cloud.google.com/appengine/docs/standard/java/migrating-to-java8

它说: -

  

要让App Engine在Java 8运行时运行您的应用程序,请添加
  <runtime>java8</runtime>
  到你的appengine-web.xml文件并重新部署应用程序。

当我尝试这样做时,我在&#34;运行时&#34;得到以下错误tag:

  

这里不允许

元素运行时

我错过了什么吗?这个GAE是我的Android应用程序的后端模块。我在Android studio上使用gradle作为开发环境。

在此之前,我还使用https://cloud.google.com/endpoints/docs/frameworks/java/migrating

成功迁移到cloudEndpoints V2

enter image description here

编辑:添加错误日志

Jan 03, 2018 3:39:52 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
SEVERE: Received exception processing D:\GitlabProjects\XushuNarrator\backend\build\exploded-backend\WEB-INF/appengine-web.xml
com.google.apphosting.utils.config.AppEngineConfigException: Unrecognized element <runtime>
    at com.google.apphosting.utils.config.AppEngineWebXmlProcessor.processSecondLevelNode(AppEngineWebXmlProcessor.java:183)
    at com.google.apphosting.utils.config.AppEngineWebXmlProcessor.processXml(AppEngineWebXmlProcessor.java:65)
    at com.google.apphosting.utils.config.AppEngineWebXmlReader.processXml(AppEngineWebXmlReader.java:132)
    at com.google.apphosting.utils.config.AppEngineWebXmlReader.readAppEngineWebXml(AppEngineWebXmlReader.java:76)
    at com.google.apphosting.utils.config.EarHelper.readWebModule(EarHelper.java:165)
    at com.google.appengine.tools.development.ApplicationConfigurationManager$WarModuleConfigurationHandle.readConfiguration(ApplicationConfigurationManager.java:414)
    at com.google.appengine.tools.development.ApplicationConfigurationManager.<init>(ApplicationConfigurationManager.java:159)

编辑2:以下是后端的gradle构建。 (从V1迁移到V2后)

//MIGRATION GUIDE
//https://cloud.google.com/endpoints/docs/frameworks/legacy/v1/java/migrating

buildscript {
    repositories {
        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.2'

//         classpath 'com.google.appengine:gradle-appengine-plugin:1.9.59'
    }
}

repositories {
    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'
//apply plugin: 'appengine'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

dependencies {
//    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.59'
//    compile 'com.google.appengine:appengine-endpoints:1.9.59'
//    compile 'com.google.appengine:appengine-endpoints-deps:1.9.59'
    compile 'javax.servlet:servlet-api:2.5'
    compile 'com.googlecode.objectify:objectify:5.1.9'

    compile 'javax.inject:javax.inject:1'

    // V2: Endpoints Framework v2 migration
    compile 'com.google.endpoints:endpoints-framework:2.0.7'

}

// 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 = "ultra-tube-89909"
        version = "2" //changed to GAE API v2

        /*
        Run the following command to initalize the Cloud SDK:
             gcloud init
        Use Application Default Credentials:
             gcloud auth application-default login
        Install the app-engine-java component:
             gcloud components install app-engine-java
         */
//        project = findProperty("appengine.deploy.project")
//        version = findProperty("appengine.deploy.version")

        def promoteProp = findProperty("appengine.deploy.promote")
        if (promoteProp != null) {
            promote = new Boolean(promoteProp)
        }
    }
}

2 个答案:

答案 0 :(得分:2)

强烈建议您保持Google Cloud SDK的最新状态,因为经常会引入错误fixes and new features。因此,我建议您通过运行以下命令来更新Cloud SDK版本:

gcloud components update

此外,根据migration documentation,升级Gradle App Engine插件需要进行以下更改,以便它可以识别新的“Java8”运行时:

classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3'

答案 1 :(得分:1)

我有完全相同的事情,但即使我有错误

  

这里不允许

元素运行时

我仍然通过Gradle重新部署后端,这一切都奏效了。然后当我检查我的谷歌云控制台时,新部署的应用引擎版本将java 8列为运行时间,我的应用程序仍然有效。所以一切似乎都好。