将Cloudendpoints后端添加到Android时出错

时间:2017-09-30 16:05:16

标签: android android-gradle google-cloud-endpoints

我有一个Test Android应用程序,并为其添加了一个cloud-endpoints后端模块。我还能够创建一个自定义类并为该类生成云端点。我也已经成功地在localhost服务器上测试了端点(8080)。

但是,当我尝试创建Async任务时,会出现许多问题。

1)我无法导入必要的com.google.api.client库。

2)我也无法在应用程序MainActivity中导入后端模块的类(即它不会显示为代码错误,但是当我在手机上运行应用程序时它确实显示为错误)

3)在执行测试运行后,我无法在Github中提交代码,因为后端文件的路径太长而无法处理。

主要活动文件如下:

package com.example.shashank_pc.testcloudendpoints;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


}
}

后端模块类文件(我为其生成了cloudendpoints)是:

@Entity
public class TempClass {

@Id
String ID;
int a;

public String getID() {
    return ID;
}

public void setID(String ID) {
    this.ID = ID;
}

public int getA() {
    return a;
}

public void setA(int a) {
    this.a = a;
}


}

app-backend的构建gradle如下:

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.google.appengine:gradle-appengine-plugin:1.9.42'
}
}

repositories {
jcenter();
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.42'
compile 'com.google.appengine:appengine-endpoints:1.9.42'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.42'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.googlecode.objectify:objectify:5.0.3'
}

appengine {
downloadSdk = true
appcfg {
    oauth2 = true
}
endpoints {
    getClientLibsOnBuild = true
    getDiscoveryDocsOnBuild = true
}
}

app模块构建文件是:

apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.1"
defaultConfig {
    applicationId "com.example.shashank_pc.testcloudendpoints"
    minSdkVersion 22
    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'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', 
{
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.code.findbugs:jsr305:2.0.1'
testCompile 'junit:junit:4.12'
compile project(path: ':backend', configuration: 'android-endpoints')
}

项目的构建gradle是:

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.3.3'

    // 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
}

0 个答案:

没有答案