Right way to use Google-Play-Services in a Java SDK - java

We have a very simple java SDK that can be imported in any android APP to do some basic tasks. One of the functionality of this SDK is to read the AAID, so we depend on Google-Play-Services.
Our current approach is use gradle java plugin and add the play-services.jar as a dependancy to our project. The latest versions of the google-play-services are packaged as .aar. So I need to know if there is any efficient way to do this or extract the aar and add the classes.jar as dependancy. While that will still work but I feel the entire solution is hacky.
I need to know what is the right way to get this done?
Thanks

Related

Calling native libraries in Flutter using Platform Channels

Using platform channels, Flutter can interop with the native platform (i.e. reading battery level). On Android, this would require calling a Java method.
I'd like to use a third-party Java SDK (for AWS Cognito). Can I put this library somewhere in my /android, and interact with it? If so, how can I do that?
Yes you can.
You can see the documentation on that or if you want you can see
tutorial. It is helpful if you are using SDK that gives you
native code for both Android and iOS, otherwise it will be difficult.
Good luck!
If you haven't already got a plugin project started, create one.
Gather the third party jars somewhere - don't put them in the pluginproject/android/... folder.
Open the plugin project in your IDE - in my case IDEA - and add the third party jars to the Java classpath. (In IDEA, click Project Structure / Modules / select pluginName_android / Dependencies tab / green PlusSign / jars or directories - and select the individual jars or the whole folder. Leave the scope as compile and don't check export.)
Implement your android-specific code in Java (or Kotlin) in pluginproject/android/src/main/java/com/yourcompany.../.../PluginnamePlugin.java, where you will now be able to use the classes declared by the third party jars.
Add the dependencies to gradle so that it will compile. In pluginproject/android/build.gradle (NOTE - there are several build.gradles) add this at the end - after the android {} section
dependencies {
implementation files('../../../java/someapi/somejar.jar')
}
The path must be relative to the pluginproject/android folder. You can specify a whole folder with this syntax instead
implementation fileTree(dir: '../../../somewhere/somefolder', include: ['*.jar'])
Run the example application provided in the plugin project.
I'm not sure why it's not possible to put the third party jars in, say, pluginproject/android/lib, but that causes a dex error for me, whereas, leaving them outside of the pluginproject/ folder works.
I've only ever used well-behaved third party jars (no JNI, don't create their own Threads, etc).
The Android side of flutter uses Gradle (the same as any other android project). If you have an existing android app, you can probably port over most of the same settings from your gradle files.
Unless you've already done that and have a system for managing the jars, I would not recommend copying the jar files directly into your project & therefore source control.
Instead, use gradle's build-in dependency resolution. You should be able to follow Amazon's android sdk set-up directions. The difference is that you'll have to hook up the calls to the SDK through method channels and write your own interop code.

Which libraries are needed for Firebase Admin SDK (Java)?

I'm trying to do Firebase Admin SDK app (with Java). I have included all the code that is provided on Firebase website, have downloaded firebase-admin library, but the problem is that I'm always missing some other library too.
I've spent my all day so far just downloading libraries. I try to compile my code, and get an error that I'm missing a library, when I download it, I'm missing the next one, and so on.
I mean, shouldn't there be some list of libraries that you need to have in for Firebase Admin SDK app? Are we really expected to download libraries just one by one all day long? There is no such list in official docs, they've just provied dependency for firebase-admin library, and I'm missing a BUNCH of others.
So in beginning I've had just firebase-admin-4.0.3 library, and I had to download the rest of these that are on the External libraries list, all one by one, and not knowing its Maven dependency at first.
Okay, problem solved. The problem was that I was using any kind of dependency manager like Maven or Gradle. I mean I was using Maven but I in another project just to download dependencies and then manually include them in project(stupid).

Restcomm Android SDK and libjingle

I am wondering how to get libjingle when checking out the SDK from git.
What I ended up doing was to add libjingle as compile dependency in build.gradle:
compile 'io.pristine:libjingle:11139#aar'
but looks like the interface is changed from what you use in the SDK, so not sure about what libjingle version to use.
Thanks.
Ok, so what we do to avoid the repo getting huge because of carrying binaries, we only place the binaries in the releases. So I'd suggest downloading latest .tar.bz2 from here and copying over native and non-native libs from restcomm.android.sdk/libs/libjingle_peerconnection*.jar and restcomm.android.sdk/libs/jniLibs/armeabi-v7a/libjingle_peerconnection*.so to the same locations in the source tree. That way they should be discoverable in the Android Studio project.
These are going to be turned into maven dependencies at some point to avoid such issues.
Now about io.pristine:libjingle:11139#aar that you used, it's going to be a problem as this build is much earlier than what we have in restcomm-android-sdk and indeed the API is different in some respects.

Android Studio - How does a library project used in an app follow with the app-release.apk

I'm using a library (https://github.com/PhilJay/MPAndroidChart) for plotting data in an android app. When app-release.apk is created by the program it is ready to be installed on the tablet I use for testing.
What is puzzling to me is how the parts of the library, which i use, follow with the release. In other scenarios, for example in Visual Studio and c# - program being installed on Window machine, libraries require dll files to be installed and registered on each targeted machine. In my scenario the library is written specifically for Android, but if I somehow managed to include a c++ or a c# library in my Android app using tools like libstdc++ or MONO, would it work the same way when it comes down to app-realease.apk?
Are all classes in a library included in the app-release.apk or just the parts that I use?
Thanks in advance and please let me know if the question is unclear before downvoting it!
Normally, when you build your APK, all the libs you have imported (jars) are included and transformed to dex files, as the rest of your code. So, yes all the classes are included, even if you don't use them.
You can use Proguard to remove them from the APK. Look at this post :
Use Proguard for stripping unused Support lib classes

How to add a non-Android Java package to the Android development environment?

So far I have been using in tutorials, examples and sample code only packages that came pre-installed with the Android SDK.
Now, I want to add a non-Android package (e.g. Jsoup).
What's the proper way of doing that (so that it becomes available to all projects)?
You can add it to a project by right clicking on your project in Eclipse and choose Build Path and Add External Archive. Select the jar to add it to your build path and it will be included in any apk you create.
One caveat is that if the jar may use part of the JDK that doesn't exist in Android.

Categories

Resources