Google App Engine is not working in Hello World app - java

As the name of the post implies, I cannot get a basic Hello World Android app to deploy after modifying my Gradle build scripts to include the Google App Engine. Here is my app's build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.tbiegeleisen.myfirstapp"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.13'
}
And here is my project's build.gradle file:
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.13'
}
}
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.13'
compile "javax.servlet:servlet-api:3.0"
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.13'
}
repositories {
mavenCentral();
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
}
allprojects {
repositories {
mavenCentral()
}
}
I am fairly certain that the script is working on some level, because the first time it ran it took a really long time. During this first time, the plugin was being downloaded. When I comment out all of the Google App Engine stuff, then the Hello World app launches with no problems. I have the feeling that Android Studio is trying execute the plugin, but either a dependency is missing, or I have a configuration problem.
When I run the app, Android Studio will spin for around 5-10 minutes, and the die with this error message:
Execution failed for task ':app:preDexDebug'.
\> com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command 'C:\Program
Files\Java\jdk.1.7.0_80\bin\java.exe'' finished with non-zero exit value 3
I don't know whether this error output will be useful, but I am including it anyway.
My hope is that an Android guru on Stack Overflow will be able to help me with this problem. For reference, I need the App Engine because I plan on using geocoding at a later time. I have already been stuck on this for several days now, and I have tried every resource I could find through Google and Stack Overflow.

I think it has something to do with your dependencies. According to Google App Engine documentation, the supported version of Java servlets is 2.5. I don't think Google App Engine supports version 3.0 yet.
Quoting from Google App Engine Java documentation:
App Engine uses the Java Servlet 2.5 standard for web applications. You provide your app's servlet classes, JavaServer Pages (JSPs), static files and data files, along with the deployment descriptor (the web.xml file) and other configuration files, in a standard WAR directory structure. App Engine serves requests by invoking servlets according to the deployment descriptor.
You have to change your dependency to this:
compile "javax.servlet:servlet-api:2.5"

Related

How to add StompProtocolAndroid to Android Studio gradle?

I'm new to java and its build scripts. I've already got a spring boot messaging service with stomp and sockjs. I want to send and receive messages from an android app. I'd like to use https://github.com/NaikSoftware/StompProtocolAndroid for the stomp client. I have problems setting it up, though.
I followed the steps described on that side, but it's kinda outdated. The server example linked there https://github.com/NaikSoftware/stomp-protocol-example-server has one build.gradle file and on my android studio there are two files, so I'm kinda confused where to put them properties.
I have cleaned android studio project with default build.gradle files. They look like this:
first file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
second file:
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.example.chatapp"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'com.android.volley:volley:1.2.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
and I added maven { url "https://jitpack.io" } to the first file right under mavenCentral()
and implementation 'com.github.NaikSoftware:StompProtocolAndroid:{latest version}' to the second file in the dependencies scope.
It syncs properly with a warning: Failed to resolve: com.githubAffected Modules: app
but when I build I get whole bunch of errors:
I tried to open them links but it returns "error 404" which means that these websites don't exist.
I also googled this error: Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
I found some "fixes", but they don't work for me, probably they're also outdated.
How can I add this library to my android app?
I've found out that I have to put maven { url 'https://jitpack.io' } inside a settings.gradle file, not the top-level build one and it works now.

Importing JDBC into Android Studio errors

I am currently working on an Android app and I am attempting to retrieve information from a MySQL database. I am trying to use JDBC as instructed by my professors, but I keep running into problems.
I have installed the MySQL Connector/ODBC 5.3, set a CLASSPATH environment variable for the driver I am attempting to use, which is "mysql-connector-java-5.1.38-bin.jar", and I attempted to import that JAR into my project.
I have attempted to import the JAR in two ways, which are the following:
File > New Module > Import .JAR/.AAR Package > import the mysql connector JAR
Then I proceeded to go to File > Project Structure > app > Dependencies > add module dependency
The other way I have attempted to do this was by adding the JAR into the "libs" folder of my project and follow the Project structure path to add a dependency from file.
I am running the latest version of Android Studio 2.0
The build completes successfully when following either of the importing steps however when doing so I get the following error when attempting to run the app:
Execution failed for task ':app:transformClassesWithInstantRunForDebug'.
> JSR/RET are not supported with computeFrames option
The only solution I found relevant to this was going to Android Studio Settings and turning the Instant Run option off.
After doing so I received the following error instead:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_77\bin\java.exe'' finished with non-zero exit value 1
The following is my build.gradle(Module:app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
applicationId "com.example.JohnDoe.myapp" //This is not actually the name or the name of the app on there but I changed this for privacy.
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
javaMaxHeapSize "2048M"
jumboMode = true
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.2.1'
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
compile 'com.android.support:multidex:1.0.1'
compile project(':mysql-connector-java-5.1.38-bin')
}
The following is a link to the whole gradle console output after turning "Instant Run" off: pastebin.com/5kj6Cgeb
Please advise me where to go from here to get the JDBC driver working so I can finish this project. Thank you for your time.
UPDATE 1: Apparently the latest JDBC driver is not fully compatible with Android and causes issues. I installed and imported the previous version (5.0.8) and so far the app at least runs. Will be attempting to implement the driver now and actually develop with it, at which time I will post another update on the outcome.
You should not use JDBC in Android Apps as it is targetted to high bandwith, reliable connections to a database server, something you will not achieve on a mobile device. Try to wrap your database in a REST web service instead.
I've read several times that people struggled with using JDBC in Android, it's just not built for beeing used in the Android ecosystem. Not every library is fully compatible with Android, your gradle output suggests that the "dexer" could not convert the jar file to a .dex.
Your provided gradle output show the following error:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
See this question for a possible solution. Ensure you are building with the right Java SDK.

Android build.gradle fail Android studio

I program with Android Studio.
Error message:
Error:Execution failed for task ':app:dexRelease'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 2
And my build.grandle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "theToolcome.theTool.theTool"
minSdkVersion 15
targetSdkVersion 22
versionCode 4
versionName "1.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services-analytics:7.3.0'
}
I didn't change anything, I only added the Google analytics. What's my problem? I search also on the stackoverflow, but nothing worked for me.
I also imported the project again, but nothing helped me.
For everyone reading.
The problem was that he downloaded a sample from the internet that contained anaylitics jar file, and he also told Android Studio to compile it for him via compile 'com.google.android.gms:play-services-analytics:7.3.0' so the end effect was that there were two libraries with mostly the same classes and that failed the build.
As the official documentation states out, your applications method references have exceeded the maximum limit:
Note: If the number of method references in your app exceeds the 65K limit, your app may fail to compile. You may be able to mitigate this problem when compiling your app by specifying only the specific Google Play services APIs your app uses, instead of all of them. For information on how to do this, see Selectively compiling APIs into your executable.
Instead of importing the entire Google Play Services, you should import the part that you use.
So instead of compile 'com.google.android.gms:play-services-analytics:7.3.0' you could use compile 'com.google.android.gms:play-services-maps:7.3.0', if what you want is GoogleMap API.
Check the Analytical Table and select the part that you want, then import it and you should be fine.
Project structure > JDK Location > Change it to a 1.7 version of the jdk.
In your message log you can scroll down to errors there can you see what the error is and maybe you can solve it at yourself. Otherwise one of the forum members can maybe help if you send the error.

Gradle Android Maven Plugin doesn't create the pom file automatically

I would like to know how to create a pom file with "Gradle Android Maven Plugin".
I followed the steps on http://www.gradle.org/docs/current/userguide/maven_plugin.html (chapter "Convention Methods"). I also created the directory "buildDir" and get no errors. The App was build successfully but nevertheless the pom file doesn't exist. I am using Android Studio IDE.
Is it possible that the newpom.xml file exists on runtime only and does not exist in my project folder buildDir after runtime? Maybe I am looking for something which can't be found.
My app/build.gradle looks like this:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
apply plugin: 'maven'
task writeNewPom << {
pom {
project {
inceptionYear '2008'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
}
}.writeTo("$buildDir/newpom.xml")
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:appcompat-v7:+'
compile files('libs/retrofit-1.5.1.jar')
}
Can someone tell me if I missed something? :)
Best Regards,
Philip
No need to create buildDir manually, it has default value and refer to /build folder that place in same folder as build.gradle file.
Did you run follow command?
gradle writeNewPom
after run it I got newpom.xml file in projectroot/build folder, BUT it contains no dependencies however I have dependencies in build.gradle file.

How to create your own library for Android development to be used in every program you write?

I am a Delphi programmer and have written, over the years, hundreds of classes and routines which I can use in every Delphi program I write.
This library is called dlib and can be used in every Delphi program by putting this folder in my library path and using one of the units in the uses section of a Delphi unit.
Being completely new to Java and Android development, I am wondering how to do this in similar way.
So my question, how can I write own classes, put them in some global folder, and use these classes and routines in every Android program I write ?
I know this is a basic question, which I can probably find out by searching Google and trying it out in Eclipse, but if someone can put me on the right track, I know I will save much time.
Thanks.
You have to create Android Library Project.
Create android project in Eclipse, enter Project Properties -> Android and check isLibrary property. Now you can add this library to your Android Application project by adding it to list on the same property page.
More detailed instructions here in Working with Library Projects section
Instructions for creating a library in Android Studio:
Create a library module
To create a new library module in your project, proceed as follows:
Click File > New > New Module.
In the Create New Module window that appears, click Android Library, then click Next.
There's also an option to create a Java Library, which builds a traditional JAR file. While a JAR file is useful for many
projects—especially when you want to share code with other
platforms—it does not allow you to include Android resources or
manifest files, which is very useful for code reuse in Android
projects. So this guide focuses on creating Android libraries.
Give your library a name and select a minimum SDK version for the code in the library, then click Finish.
Once the Gradle project sync completes, the library module appears in
the Project panel on the left. If you don't see the new module
folder, make sure it's displaying the Android
view.
Convert an app module to a library module
If you have an existing app module with all the code you want to
reuse, you can turn it into a library module as follows:
Open the module-level build.gradle file.
Delete the line for the applicationId. Only an Android app module can define this.
At the top of the file, you should see the following:
apply plugin: 'com.android.application'
Change it to the following:
apply plugin: 'com.android.library'
Save the file and click Tools > Android > Sync Project with Gradle
Files.
If your library is in .java files composed of java code. There's a really detailed tutorial of how to use the library at mobile.tutsplus.com. Link below:
http://mobile.tutsplus.com/tutorials/android/android-essentials-creating-android-compliant-libraries/
For Example I wanted to use the Pull To Refresh library by Chrisbanes at Github.com here https://github.com/chrisbanes/Android-PullToRefresh/tree/master/library. The library's structure is in the form of an Android app. It has the form like below:
res/
src/
AndroidManifest.xml
pom.xml
project.properties
How to use on Eclipse:
Create new project in Eclipse. Give a name to your project. Select
"Create project from existing source". Select the location of the
root folder containing the above mentioned files in "Location".
Select your target and click finish.
Select properties of the newly project you created. Select "Android"
option. Select the "Is Library" checkbox if it's not already
selected. close properties.
Add a reference to the library from the project that is going to use
this library. Select your project that uses this library. Open
Properties. Select "Android" option. At the bottom on the "Is
Library". Don't select checkbox of "Is Library". Click "Add" button
on the right. Your project that you created on step 1 and 2 should
be listed ready for selection. select it and click apply. close
properties.
You're ready to reference the classes from your project.
With java, you create a Java Archive (jar) that contains all your classes (*.class files) of that library and the jar file is your library.
To use it, simply add it to the classpath.
(For "jar" and "classpath": basic Java concepts, please use google to find tutorials, you'll have to understand those concepts anyway, the sooner, the better ;) )
Convert all of your class in Java and make a jar file. Use this jar in your android project by copying in libs/ folder and then adding in to build path. Make a clean of project and then run it.
If you're using new android studio version and gradle 7.0.3
Android Studio Arctic Fox | 2020.3.1 Patch 3
Build #AI-203.7717.56.2031.7784292, built on October 1, 2021
Runtime version: 11.0.10+0-b96-7249189 amd64
VM: OpenJDK 64-Bit Server VM by Oracle Corporation
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 2
Registry: external.system.auto.import.disabled=true
Creating module
Create new project with empty activity
Click file -> new -> new module -> and choose android library.
After new module created you can add java class or something for
your library
Export library to AAR file
You can check this for more information
Export library to jitpack.io
Set this file like this
build.gradle (project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (module:app)
plugins {
id 'com.android.application'
}
android {
lintOptions {
abortOnError false
}
}
android {
compileSdk 31
defaultConfig {
minSdk 16
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
build.gradle (module: YourLibraryName)
plugins {
id 'com.android.library'
id 'maven-publish'
}
task androidSourcesJar(type: Jar) {
classifier 'sources'
from android.sourceSets.main.java.srcDirs
}
project.afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId 'com.github.YourGithubUsername'
from components.release
artifact androidSourcesJar // optional sources
}
}
}
}
android {
compileSdk 31
defaultConfig {
minSdk 16
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Create file jitpack.yml in root project (YourProjectName -> Gradle -> right click -> new -> file -> name it "jitpack.yml" and put this code to jitpack.yml file
jdk:
- openjdk11
before_install:
- chmod +x gradlew
install:
# - ./gradlew build :lib:publishToMavenLocal
- ./gradlew build publishToMavenLocal
Share your project to Github
Visit jitpack website
Follow this step for upload your library

Categories

Resources