I'm trying to migrate to Android studio and my app engine code uses the Entity framework listed below
import javax.persistence.Entity;
import javax.persistence.Id;
#Entity
public class AppVersion {
#Id
private String applicationName;
private int minVersionRequired;
public String getApplicationName() {
return applicationName;
}
public int getMinVersionRequired() {
return minVersionRequired;
}
public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}
public void setminVersionRequired(int minVersionRequired) {
this.minVersionRequired = minVersionRequired;
}
}
Just creating a backend in Android Studio (0.5.6) doesn't work, I can't import javax.persistence.*
From this link I discovered that I needed to create a persistence.xml file (this was automatically created in Eclipse). I just can't figure out where in the file structure it is supposed to go. I understand it needs to be in the META-INF folder but I don't know where that corresponds for gradle (or if it has to be created in the gradle build file).
Current file structure:
-src
-main
-java
-com.package.test
class files
-webapp
-css
-js
-WEB-INF
Gradle build file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.1'
}
}
repositories {
mavenCentral();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = 1.7
targetCompatibility = 1.7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.1'
compile 'com.google.appengine:appengine-endpoints:1.9.1'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.1'
compile 'javax.servlet:servlet-api:2.5'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
}
}
Android Studio's App Engine samples don't use JPA.
However if you want to use JPA, you need to add the JPA dependencies, this describes where you might find out what those are https://developers.google.com/appengine/docs/java/datastore/jpa/overview-dn2
So these (or some subset of these)
asm-4.0.jar
datanucleus-api-jpa-3.1.3.jar
datanucleus-core-3.1.3.jar
jdo-api-3.0.1.jar
datanucleus-api-jdo-3.1.3.jar
datanucleus-appengine-2.1.2.jar
geronimo-jpa_2.0_spec-1.0.jar
jta-1.1.jar
Look on maven.org for those dependencies will reveal how to include them in build.gradle files as compile dependencies:
asm-4.0 :
compile 'org.ow2.asm:asm:4.0'
datanucleus-api-jpa-3.1.3 :
compile 'org.datanucleus:datanucleus-api-jpa:3.1.3'
and so on.
You want the versions to be exactly as they are in the appengine sdk to ensure compatibility. Also make sure you run the enhance task on your project.
Try adding following to the build.gradle
compile group: 'javax.persistence', name: 'persistence-api', version: '1.0'
Related
I am trying to implement gRPC and now I'm having all sorts of issues, but I just don't get what I'm doing wrong. I am following this doc:
https://github.com/grpc/grpc-java/blob/master/README.md
And now I keep getting such errors when I'm trying to build my project
error: package com.google.protobuf.GeneratedMessageV3 does not exist
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
In my Android Studio external libraries I have protobuf-java-3.12.1 jar.
In my project gradle file I've added this to dependencies:
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.14'
And in my app gradle file:
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
In dependencies I added:
implementation 'io.grpc:grpc-okhttp:1.35.0'
implementation 'io.grpc:grpc-protobuf-lite:1.35.0'
implementation 'io.grpc:grpc-stub:1.35.0'
compileOnly 'org.apache.tomcat:annotations-api:6.0.53'
implementation 'com.google.protobuf:protobuf-javalite:3.12.1'
And outside of the android tag:
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.12.1"
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.35.0'
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}
Finally, my proto file:
syntax = "proto3";
import "google/protobuf/timestamp.proto";
option java_package = "com.xxx.xxx.proto.log";
option java_outer_classname = "MyClass";
message MyObject {
string name = 1;
string unit = 2;
oneof value {
bool bool_value = 3;
sint32 int32_value = 4;
uint32 u_int32_value = 5;
google.protobuf.Timestamp timestamp_value = 6;
}
}
When I run: protoc --version in terminal, this is the output:
libprotoc 3.12.1
Do I have to add something else or I missed something in my Gradle setup?
It looks like you are hoping to use protobuf lite (as is normal for Android projects):
implementation 'io.grpc:grpc-protobuf-lite:1.35.0'
...
implementation 'com.google.protobuf:protobuf-javalite:3.12.1'
However, currently you are generating full protobuf code. You need to tell the java and grpc-java code generators to generate for lite via options. As seen in the grpc-java Android helloworld example:
protobuf {
...
generateProtoTasks {
all().each { task ->
task.builtins {
java { option 'lite' }
}
task.plugins {
grpc { option 'lite' }
}
}
}
}
I am coming because I can't make work my communication between my API (Go) and my client (Android).
I have this protobuf file:
syntax = "proto3";
option java_package = "com.emixam23.rushpoc.protobuf";
option java_outer_classname = "HelloWorld";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
The protobuf file comes from the example of https://grpc.io/docs/quickstart/go.html, I just didn't implemented the SayHelloAgain. What i am trying to achieve is, from my android app, SayHello to my Go API and get a reply...
For android, I followed that tutorial (https://grpc.io/docs/quickstart/android.html) in order to, from the protobuf file, to communicate with my API. However, there is a stub, comming from I don't know where.
So I searched about how to create a stub (https://grpc.io/docs/tutorials/basic/android.html) and nothing.. ManagedChannelBuilder doesn't exist and I can't find the way to install it..
PS: to generate my Java class from the protobuf file, I followed that tutorial: https://proandroiddev.com/how-to-setup-your-android-app-to-use-protobuf-96132340de5c
Am I in the right direction or totally wrong?
My project structure:
APP build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.rushpoc.emixam23.androidapp"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//Protobuf
implementation 'com.google.protobuf:protobuf-lite:3.0.0'
implementation 'io.grpc:grpc-okhttp:1.13.2'
implementation 'io.grpc:grpc-protobuf-lite:1.13.2'
implementation 'io.grpc:grpc-stub:1.13.2'
}
protobuf {
generatedFilesBaseDir = "$projectDir/generated"
protoc {
// You still need protoc like in the non-Android case
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
// The codegen for lite comes as a separate artifact
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.13.2'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
java
}
task.plugins {
grpc {}
}
}
}
}
TOP-LEVEL/Root build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.protobufVersion = '0.8.6'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "com.google.protobuf:protobuf-gradle-plugin:$protobufVersion"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I haven't checked the entire gradle files yet but I see in your screenshot the .proto file was in src/main/protobufs, which was not following either of the tutorials you mentioned. The protobuf gradle plugin does not detect this directory by default. Therefore I suggest you change it into the default directory src/main/proto. If you would like to insist putting the .proto file in src/main/protobufs, you might need let the protobuf gradle plugin know it by adding
// see https://github.com/google/protobuf-gradle-plugin#customizing-source-directories
sourceSets {
main {
proto {
// In addition to the default 'src/main/proto'
srcDir 'src/main/protobufs'
}
}
}
After that, the protobuf gradle plugin will generate the java code if there's no other mistake.
This is my project's build.gradle file. I am trying to create maven url dynamically. When I provide the commented hardcoded string, it works fine but when I give the uncommented dynamic string, it messes up.
foo.class is a string too. I have no idea what is wrong in this. Any help will be appreciated.
apply plugin: 'java'
def foo = System.getenv().get("ANDROID_HOME")
//def foo = "/Users/someone/Library/Android/sdk"
repositories {
jcenter()
maven { url "$foo/extras/android/m2repository" }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-annotations:25.1.1'
}
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
For this particular case (Android support library dependency in java module) you can use snippet like this:
def logger = new com.android.build.gradle.internal.LoggerWrapper(project.logger)
def sdkHandler = new com.android.build.gradle.internal.SdkHandler(project, logger)
for (File file : sdkHandler.sdkLoader.repositories) {
repositories.maven {
url = file.toURI()
}
}
You have to add Android Gradle plugin to classpath dependency (but don't apply it):
classpath 'com.android.tools.build:gradle:2.2.3'
Reference: https://github.com/JakeWharton/butterknife/blob/master/butterknife-compiler/build.gradle
I've got a problem with my javafx ported app on android.
After first launch it looks like that:
But when i go to home screen and then rejoin to application it looks as it should be.
build.gradle:
buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.1.1'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
mavenCentral()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'pl.siemaeniu500.wszywka.main.Main'
ext.CHARM_DOWN_VERSION = "2.0.1"
dependencies {
compile "com.gluonhq:charm-down-common:2.0.1"
//compile 'com.gluonhq:charm-glisten:3.0.0'
compile 'com.gluonhq:charm:2.1.1'
compile files('D:/Android/Sdk/platforms/android-21/android.jar', 'C:/Users/Kamil/Documents/NetBeansProjects/WszywkaSounds/jfxdvk-8.60.8.jar')
androidRuntime 'com.gluonhq:charm-android:2.1.1'
iosRuntime 'com.gluonhq:charm-ios:2.1.1'
desktopRuntime 'com.gluonhq:charm-desktop:2.1.1'
desktopCompile 'com.github.sarxos:webcam-capture:0.3.10'
}
jfxmobile {
downConfig {
version = '3.0.0'
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
//compileSdkVersion 24
//buildToolsVersion "24.0.3"
androidSdk = 'D:/Android/Sdk'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}
main application class:
package pl.siemaeniu500.wszywka.main;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Screen;
import javafx.stage.Stage;
/**
*
* #author Kamil
*/
public class Main extends Application {
#Override
public void start(Stage stage) throws Exception {
Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
Parent root = FXMLLoader.load(getClass().getResource("FXML.fxml"));
Scene scene = new Scene(root, visualBounds.getWidth(), visualBounds.getHeight());
stage.setScene(scene);
stage.setMaximized(true);
//new FXMLController().initialize();
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
What can cause that?
When you set the scene size:
Scene scene = new Scene(root, visualBounds.getWidth(), visualBounds.getHeight());
you are already taking the whole screen on your device, so you don't need to set this:
stage.setMaximized(true);
Removing that line should fix the issue.
As for the build script, you can simplify the dependencies.
In a first step, remove charm-down-common. If you are not using charm glisten you can remove all charm-* dependencies. If you use it, you will use the new version 4+ (uncomment the line below).
dependencies {
// compile 'com.gluonhq:charm:4.0.1'
compile files('D:/Android/Sdk/platforms/android-21/android.jar', 'C:/Users/Kamil/Documents/NetBeansProjects/WszywkaSounds/jfxdvk-8.60.8.jar')
desktopCompile 'com.github.sarxos:webcam-capture:0.3.10'
}
As for the android and jfxdvk jars, those shouldn't be there. The plugin will manage that for you.
dependencies {
// compile 'com.gluonhq:charm:4.0.1'
desktopCompile 'com.github.sarxos:webcam-capture:0.3.10'
}
Reload the project (Project root, right click, Reload Project):
and you will see them under Dependencies -> Compile for Android:
I want to use realm database in my app for that i add this lines to my build.gradle file in app
apply plugin: 'realm-android'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:1.1.0"
}
}
and this is my table code:
public class Country extends RealmObject {
#Ignore
public static String NAME="name";
#Ignore
public static String POPULATION="population";
#PrimaryKey
private String name;
private int population;
public Country() { }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPopulation() {
return population;
}
public void setPopulation(int population) {
this.population = population;
}
}
but when I use this code and nothing else "I mean never use country table" I getting this error when run my app:
An exception has occurred in the compiler (1.8.0_05). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for rx.Observable not found
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
my app.gradle file
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.sss.ddd"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
repositories {
maven { url "https://jitpack.io" }
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
}
and this is my project.gradle file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath "io.realm:realm-gradle-plugin:1.1.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
}
can anyone help me abou this?
thanks.
Thanks all For your attentions but I found my solution.
I add this lines to my project Gradle file:
allprojects {
repositories {
jcenter()
maven {
url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo'
}
}
}
and this to my app gradle file
compile 'com.uphyca:stetho_realm:0.9.0'
compile 'io.reactivex:rxjava:1.1.0'
compile 'com.facebook.stetho:stetho:1.3.1'
I don't know why I should add this lines and realm documentation never refer to this but know my project works fine.
I know this is wired behavior but its work.
please share me if you know a better answer.
Updating JDK to version 1.8.3 solved the issue.
JDK can be downloaded from
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Setting up JDK on android can be done using
How to set Java SDK path in AndroidStudio?
This is how I solved the problem:
1.) Create a new package and name it rx
2.) Inside this package add a class named Observable, empty class.
It compiles fine now.