ORMLite on Android using javax.persistence annotations - android

We have developed a web service and now are building an Android application to communicate with the web service. We use persistence in our web service and would also like to use persistence in our Android app. We figured that ORMLite was the way to go for persistency on Android and we are hoping that the javax.persistence support would be good enough for our app. I was hoping that I would be able to copy the web service's data model to the Android app and not having to modify the annotations.
So I tried copying the model classes and adding ormlite-android-4.41.jar and ormlite-core-4.41.jar to my Android project. Unfortunately this did not do the trick. My IDE can't find the classpaths for the javax.persistence annotations. Do I need additional libraries? I can't anything on that in the documentation.

If you are using maven. You can add this to your pom.xml:
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
Alternatively you can download the jar file straight from the maven repository here then add it to the classpath. By the way, the #Table(name = "table_name") is not supported. You should substitute it with #Entity(name="table_name").

Interesting question. If the javax.persistence annotations aren't in the Android JDK then I'm not sure you should be using them.
That said, if you want to use them, you should be able to get the java files from a JDK source jar and include them in your own project. Just copy the annotations that you actually use out of the source jar into the appropriate javax/persistence path.
The ORMLite support for the javax.persistence annotations is far from perfect. If you have any problems please let me know so I can improve them.

Related

How do I include required aar and jar files in a Xamarin Android app? What is the AndroidLibrary build action for?

We use Xamarin Forms and I have been tasked with integrating a 3rd party AAR library from a business partner and I don't have control over the library or its dependencies. This library itself is distributed using Maven, which works great in Android Studio but is a pain in Xamarin, and it has many dependencies on both libraries that are standard in Android as well as other proprietary libraries.
Since I only need to interact with a small portion of the public API of the main library, I've created an Android library (AAR) wrapper project in Android Studio that only exposes the functionality I need and does not use any types that do not already have bindings.
I have created an Android binding project against the AAR wrapper library, and it compiles in Visual Studio without any warnings or errors.
I've created bindings for other libraries in the past and have the Xamarin binding documentation multiple times and searched online, but the part I'm missing is how to include the required/reference JAR/AAR files in the compilation process and the final Android application. Most of the standard libraries that I need already have NuGet packages (Androidx, Google Play Services, etc)., but the binding library compiles without complaint - so how do I include the other required libraries?
Do I really have to create a binding project for each required AAR/JAR and add as a reference? I don't need to interact with the types or resources in these libraries directly from Xamarin since I only interact with the the types/methods exposed in the wrapper AAR (e.g. I don't think I really need a Xamarin binding). Is there a way to simply have Xamarin process the required AARs and JARs without creating a Xamarin binding project for every library that doesn't already have a NuGet package? There are many many dependencies which makes this theoretically possible, but not in practice. There must be an easier way...
I noticed there is an AndroidLibrary build action that the documentation says can be used to directly reference an AAR/JAR file in a Android application, but I can find no examples of how to use this in practice. What does this build action do? How is it supposed to be used? https://learn.microsoft.com/en-us/xamarin/android/deploy-test/building-apps/build-items#androidaarlibrary
Thanks in advance for any help or direction on the best way to do this.

How do I use included Android dependencies from within the NDK?

I am trying to use SQLCipher within Android. They made it very easy to integrate by adding the dependency:
implementation 'net.zetetic:android-database-sqlcipher:4.2.0#aar'
They have nice and simple examples of then using this in Java, but my application is c++ and I am using the NDK. SQLCipher is primarily C code so I know that this is linking against some compiled C code. Are the headers available for use? Where are these dependencies being installed. I am an iOS developer new to Android so I feel like this should simple but I am just missing something.
There's currently no support for consuming C/C++ dependencies from an AAR. We're working on this here: https://github.com/android-ndk/ndk/issues/916
But I should note that even when that is complete, sqlcipher does need to choose to expose that library. The AAR would not currently contain includes, and it may not be a stable API so they may choose not to expose it.
For a library to be usable directly by ndk, you'd need a .so version of it to link against. If you're including the library like this, you'd use JNI to access it via Java.
I'd recommend against hacking something up to access their .so files directly. Its quite possible their Java code has business logic that prevents errors or initialized things that are not set up properly if you go right against their .so file.

How do you include a networking library within another library?

I am working on writing an SDK for a client. Part of the SDK requires me to interface with a good 20-30 endpoints. How I have always done this in the past is simply used Retrofit and OkHttp for the API interface. I recently discovered, however, that you cannot use 'nested' library references within a library.
My question is, how do I go about using Retrofit in this current library I am making so that it can be used on other devices? Do I just need to clone the repo, copy the code into my project and go from there? Or is there a simpler method?
Thanks all.
Your can use maven transitive dependency.
Or AAR have no problems with nested jar files. From documentation
A library module can include a JAR library
You can develop a library module that itself includes a JAR library; however you need to manually edit the dependent app modules's build path and add a path to the JAR file.
I use this approach for okhttp.

Import excel (.xlsx) file data in android

I have a problem regarding Excel(.xlsx) file import in Android SQLite database, I am using Poi jar file but finding following Runtime error.
java.lang.VerifyError: org/apache/poi/xssf/usermodel/XSSFWorkbook
How can i resolve this problem ? please help me.
If you are using maven try the following
<!-- http://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.14</version>
</dependency>
if not just download the jar file and add in your built path.
Java on Android has some intricacies which require some more work due to duplicate classes in some jars, the number of methods that POI has and some javax.* code that is included via transitive dependencies.
There are multiple approaches that were used by others over time:
Recently I prepared a sample at https://github.com/centic9/poi-on-android/ which allows to build a combined jar-file which includes everything needed for Apache POI in a way that also works on Android
The project at https://github.com/andruhon/android5xlsx tries to provide ready-made jar-files that are patched and adjusted to work on Android
Previously for Android versions below 5, https://github.com/andruhon/AndroidReadXLSX did provide a slightly approach, still with ready-made jar-files being provided
Please try to use one of those and report back if you succeed. The first one is a rather new approach, but it would allow to re-package newer versions of Apache POI rather quickly compared to the other two which are a few versions behind already.

Shared classes for Android and Spring MVC projects

I've a client-side Android project and a server side Spring MVC project. Some classes defining rest messages exchanged between client and server are common, and could be useful to define a common project to share the classes.
For now I duplicated all the classes in both projects. Client-side classes use Android library (principally Parcelable) and others like jackson for JSON and simpleframework for XML. Server-side classes use Jackson for Json, JAXB for XML and Hibernate for ORM.
I know about how to import these classes in Android Project, it simply need to include hibernate annotation and others in the android libraries, but i'm a little confused about importing an Android project in Spring MVC.
How i have to define this shared project: as a normal Java project, as an Android project? And it's correct/possible to import the Android library in a Spring project or there will be conflicts with the Java library? How to solve?
As last possibility I'm considering to remove the Android dependency substituting Parcelable with Serializable, but I prefer to use Parcelable for its better performances.
I'm using Eclipse Spring Tool Suite with Android Development Tool plugin and Maven.
Including the android project in a Spring MVC project doesnt make sense
You should build a standalone standard java project (that compiles and is built to a JAR file) that contains all the code that is shared between the android and springmvc project.
This common JAR file should then be included in both the android project and Spring MVC project. Pretty simple really :)
If you are using Maven you can include it as a dependency (Which will be the cleanest approach) if not then just manually include the JAR in each of the projects.

Categories

Resources