Google endpoint framework breaks for Android Studio 3.4 (gradle 5.1.1) - google-app-engine

I have a project that uses Google App Engine with Android.
I got the following "gradle project sync failed" error after I upgraded to Android Studio 3.4 (gradle 5.1.1).
It was working well prior in the previous android studio version which uses gradle 4.10.1.
Any pointers are welcomed. do tell me if you need me to provide more information
Caused by: java.lang.NoSuchMethodError: org.gradle.api.tasks.SourceSetOutput.getClassesDir()Ljava/io/File;
at com.google.cloud.tools.gradle.endpoints.framework.server.EndpointsServerPlugin$2$1.execute(EndpointsServerPlugin.java:108)
at com.google.cloud.tools.gradle.endpoints.framework.server.EndpointsServerPlugin$2$1.execute(EndpointsServerPlugin.java:98)
the following is the build.gradle file for the backend module.
This was after I migrated to GAE V2 using the migration guide (https://cloud.google.com/endpoints/docs/frameworks/java/migrating-android)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.2'
}
}
repositories {
jcenter()
}
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 {
// V2: Endpoints Framework v2 migration
implementation 'com.google.endpoints:endpoints-framework:2.0.9'
implementation 'javax.inject:javax.inject:1'
implementation 'javax.servlet:servlet-api:2.5'
implementation 'com.googlecode.objectify:objectify:5.1.9'
}

Updating from:
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
to:
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.3'
Fixed this problem in my project

to get it working again, I had to comment off the following from the build.gradle (module:app )
//buildscript {
// repositories {
// jcenter()
// }
// dependencies {
// // V2: Add the new Endpoints Framework plugin dependencies
// classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.3'
// }
//}
instead, add the classpath into the build.gradle (project)
buildscript {
repositories {
jcenter()
google()
}
dependencies {
// V2: Include this dependency when using Endpoints Framework v2
classpath 'com.google.guava:guava:24.1-jre'
//**moved from the build.gradle in module:app**
classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.3'
///... <snips> the rest of the build.gradle file

Related

Getting error when I am trying to connect my Android Studio to Firebase following the docs

Where Should I paste this?
AS in docs it shows to paste this in Root-level (project-level) Gradle file (/build.gradle):
but this is showing error when I am trying to paste this.
allprojects {
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
}
Following the video given by Firebase website as I have noticed that many things have changed in Android studio so its hard for me to follow the video.
my build.gradle file has these
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "PUCabz"
include ':app'
WHere should I paste the "allprojects repositories" code
I resolved this issue by commenting out 'dependencyResolutionManagement' section which is present in the settings.gradle.
Go to Gradle Scripts -> settings.gradle -> comment out 'dependencyResolutionManagement'
//dependencyResolutionManagement {
// repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
// repositories {
// google()
// mavenCentral()
// }
//}
Then paste the all project repository in
Gradle Scripts -> build.gradle -> paste it below 'plugins' section
like this-
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
}
allprojects {
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
}

Google App Engine with Firebase - can't add dependencies

I'm trying to connect a backend module in Android Studio to Firebase using the tutorial here - https://cloud.google.com/solutions/mobile/firebase-app-engine-android-studio#adding_dependencies_to_the_backend_module
I cannot add the dependencies for some reason. I can't find them on the list. If I try to add them manually, I get a Gradle sync error.
For the main app module, Firebase is connected and it's functioning correctly. I set this up using Android Studio's build in Firebase tool. I've tried using this tool again but it's made no difference.
Here's my build.gradle for the backend:
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 'javax.servlet:servlet-api:2.5'
compile 'com.google.appengine:appengine-api-1.0-sdk'
compile 'com.google.firebase:firebase-server-sdk'
compile 'org.apache.httpcomponents:httpclient'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
}
Here's the error I get if I add the dependencies manually, as shown in the code above:
Click here
You're probably getting errors on these dependencies. They don't have versions specified:
compile 'com.google.appengine:appengine-api-1.0-sdk'
compile 'com.google.firebase:firebase-server-sdk'
compile 'org.apache.httpcomponents:httpclient'
Every maven dependency requires a group id, artifact id, and a version string.
Also, the "firebase-server-sdk" dependency doesn't make sense to me. Access to firebase backend services is now done through the Admin SDK.
My guess is that the tutorial you linked to is simply very much out of date, and you can no longer follow it exactly, but maybe you can still learn something from it otherwise.

Gradle Could not resolve: com.microsoft.sqlserver:sqljdbc4:4.0

Please help me to resolve this error...
Added Dependency in build.gradle
**// https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4
testCompile group: 'com.microsoft.sqlserver', name: 'sqljdbc4', version: '4.0'**
After Refresh Gradle Project, getting the error below:
**Could not resolve: com.microsoft.sqlserver:sqljdbc4:4.0**
"It worked for me after adding in locally, here are my Steps in Eclipse Neon."
Step 1.
create 'lib' folder under main project
Step 2.
copy the jar file 'sqljdbc4' to lib folder
Step 3.
Add below dependency in 'build.gradle' file
repositories {
jcenter()
mavenCentral()
flatDir {
dirs 'lib'
}
}
dependencies {
compile name: "sqljdbc4-4.0"
}
Step 4.
Right click on main Project and refresh gradle
I am not sure about your build.gradle file.
It should work.
testCompile group: 'com.microsoft.sqlserver', name: 'sqljdbc4',
version: '4.0'`
is available in maven repository.
Did you gave
repositories {
mavenCentral();
}
as the repository in your build.gradle file? If you gave this , then it should work.
If it is not working please share your full build.gradle file here, and the error trace so that we can get more idea about your question
To resolve the dependency properly you need to add the maven url where the jar is located at.
Add this under repositories:
maven { url "http://repo.spring.io/plugins-release/" }
Should look something like this (this declares multiple repositories):
repositories {
mavenCentral()
maven { url "https://repo.spring.io/milestone" }
maven { url "http://repo.spring.io/plugins-release/" }
}

Android Studio GAE Project Deploy: Class file is Java 8 but max supported is Java7

I have a Google App Engine project in Android Studio. In the past I have successfully deployed to my project to GAE many times. However, some project setting has changed and I can no longer deploy. I get the message:
java.lang.IllegalArgumentException: Class file is Java 8 but max supported is Java 7: javax/ws/rs/ApplicationPath.class in /Users/rob/AndroidStudioProjects/SpeedyMovingInventory/backend/build/exploded-app/WEB-INF/lib/javax.ws.rs-api-2.1-m02.jar
Unable to update app: Class file is Java 8 but max supported is Java 7: javax/ws/rs/ApplicationPath.class in /Users/rob/AndroidStudioProjects/SpeedyMovingInventory/backend/build/exploded-app/WEB-INF/lib/javax.ws.rs-api-2.1-m02.jar
Please see the logs [/var/folders/cn/3ktx4pj50hs7338v88b0sckh0000gn/T/appcfg3087406806803083082.log] for further information.
I have tried to set the source and target compatibility in my build.gradle, it is shown below:
// 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()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.34'
}
}
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.34'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.34'
compile 'joda-time:joda-time:2.8.2'
compile 'net.sargue:mailgun:1.0.0'
compile 'com.google.code.gson:gson:2.7'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
// Set this dependency if you want to use Hamcrest matching
testCompile 'org.hamcrest:hamcrest-library:1.1'
testCompile fileTree(include: ['*.jar'], dir: '/Users/rob/appengine-java-sdk-1.9.34/lib/impl')
testCompile fileTree(include: ['*.jar'], dir: '/Users/rob/appengine-java-sdk-1.9.34/lib/testing')
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
}
I have also used Android Studio to generate a sample GAE module and successfully deployed the sample to GAE. I compared the gradle files and settings and I don't see any differences. Please help, what am I doing wrong?
After lots of research, I have figured a fix. The library 'net.sargue:mailgun:1.0.0' apparently has a dependency of some sort on a java 8 lib (or something along those lines). I don't know why this hasn't caused me issues in the past, but it is now. Upgrading the lib to 'net.sargue:mailgun:1.3.2" resolves the issue.
I have had a conversation with the author of the mailgun library:
https://github.com/sargue/mailgun/issues/11
He had a dependency which were updated to Java 8, he fixed it in the new release.

Android Studio with AppEngine - Gradle dependencies

I'm trying the simplest example with Android Studio to create my own backend with this tutorial.
Backend is built and it seems like it's creating the client libraries as well.
The server starts and I can access it from localhost:8080
When I try to build my android app now, the app cannot find following classes
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.extensions.android.json.AndroidJsonFactory;
import com.google.api.client.googleapis.services.AbstractGoogleClientRequest;
import com.google.api.client.googleapis.services.GoogleClientRequestInitializer;
neither the client model (called Registration, as in the sample).
How do I have to setup the dependencies of the project in gradle, so that the project can find the correctly generated client libraries?
Currently:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
applicationId 'de.unicate.cloudchat'
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services:4.4.+'
compile 'com.android.support:support-v4:+'
}
Shouldn't that happen automatically in Android Studio?
I also encountered the same problem. I added the dependencies from this Stack Overflow Answer.
Add these dependencies:
compile ('com.google.api-client:google-api-client-android:1.17.0-rc') {
exclude module: 'httpclient'
}
compile ('com.google.http-client:google-http-client-gson:1.17.0-rc') {
exclude module: 'httpclient'
}
See this example
The newest version of the wizards adds the dependencies to your project automatically(as you mention), what version of android studio are you using?
The modified build.gradle file will have the extra dependency
compile project(path: ':<backend-module-name>', configuration: 'android-endpoints')

Resources