I may have bitten off more than i can chew here. I've moved outside of my .net / visual studio comfort zone for the first time in order to play with the Android SDK. I'm (attempting) to use IntelliJ.
I have a single module project. I want to "reference" the google gson library. After hours of tooling around in the project structure dialog, googling, reading the IntelliJ help and laughing at my own ineptness I managed to at least get a successful build.
However when i deploy to the virtual device, I note the "logcat" shows:
Could not find class
'com.google.gson.Gson', referenced
from method
com.example.HelloW$ClientThread.run
I'm assuming this is less to do with my code, and everything to do with how i ended up referencing the gson-1.7.1.jar file?
Can somebody tell me in the simplest terms how i add that dependancy successfully?
Adding jar file to Dependencies is easy and you can find the details in the official documentation.
Make sure that the library scope is set to Compile.
Here is the sample showing "lib" library that contains a couple of jars added to the module dependencies:
Related
I have recently begun maintaining an Android app that is not compliant with Google's requirement for 64-bit native libraries. The app itself does not directly depend on native code but in the generated apk a native library named libcproxy gets included. I can only assume that this is needed by one of the apps dependencies but so far I have not had any luck in finding the artefact in question. The shared library also seems a bit elusive as I have not been able to find many references to it online.
Is there perchance a gradle command or similar that can shed some light on which artefact includes the library?
I have tried excluding the shared library in the hope, that I might get an unsatisfied link error but so far I have not been able to make the app crash due to missing the library.
You can display a dependency tree with :
gradlew app:dependencies
Trying to develop android LPA system app for eSIM with the new Pie API.
The doc says to extend the abstract EuiccService class. But this class is not in the official SDK, and the link in the docs just leads to corresponding file in the android source repo.
I tried using this file/class as a dependency, but it references other internal android classes/annotations and causes build/IDE errors.
Does anyone have an idea how to use this?
Do I really have to pull android src code and somehow reference required class from it?
EDIT: I think I've solved it, found couple of potential solutions, but they were a bit cumbersome. Used the android.jar from here: https://github.com/anggrayudi/android-hidden-api (contains modified android.jar with hidden APIs and internal resources). It didn't work when i replaced the whole file and resulted strange build errors, but i manually transferred the android\service\euicc\ folder to original android.jar of android-28 sdk and it works perfectly (class is available and apk builds without issues). And no need to waste time pulling and building AOSP.
EDIT #2: apparently not fully fixable atm. There's issue with android gradle plugins (at least 3.2.x-3.3.x) where during full sync some build task generates mock classes from android.jar and process fails if it's modified (discussion is here: https://github.com/anggrayudi/android-hidden-api/issues/46). Error looks like this:
Failed to transform file 'android.jar' to match attributes {artifactType=android-mockable-jar, returnDefaultValues=false} using transform MockableJarTransform
There's a workaround for that, though inconvenient:
when you need a full sync for the project, replace the android.jar with original, run sync, restore modified android.jar, the IDE now will run indexing and classes will be available again with build working until next full sync.
Will update this post if/when it's fixed or new solution is found.
EDIT#3: here's probably a final solution for EuiccService case (turned out pretty obvious):
Instead of adding 'android/service/euicc' folder to android.jar, just put it in a separate library and add it as a compileOnly dependency. Since the classes were not in the SDK, the lib should not cause conflict (would be the case if you need to use modified framework or access hidden APIs in already existing classes).
If you are going to create a System APP, you will do it in several ways:
You could call a part of the SystemAPI (a method for example) by reference.
You could make the aplication as a part of the AOSP Project (Downloading the AOSP code, and introducing your app as part of packages/apps/)
You will be able to access system APIs on a rooted device or if you have system permissions (this happens when you flash your app into the device as part of the system image).
However, if you want to be able to call the EuiccService class from Android Studio (for coding purposes), you'll need to add the Android framework jar to your project.
The steps are provided below:
First, you will have to download and build AOSP and generate a framework jar for your target Android version. Check the documentation here to get an idea of how to download and build AOSP.
After a successful build all framework classes are compiled into a jar called classes.jar which can be found at the location out/target/common/obj/JAVA_LIBRARIES/framework_intermediates.
Get this classes.jar and add it to your Android project as a jar file.
Gradle sync the project and start coding.
Please beware that you WILL NOT BE ABLE TO run this app on an Adnroid device where you do not have system permission for this app.
I'm a beginner in Android programing, and I'm working with android studio...now i wander what is the best way for installing open sources libraries from gitHub.
my question is from organization principles point of view-
should i create a new package for every library and put all the library source code as is in that package? should the package be in the source.main.java folder?? (the one that the android studio creates automaticly).
sorry for the dumb question...it's just that im taking my first baby steps in a big scale program and i don't want to loose my head in the future because of bad organization practices.
There's no right answer to this question. A few wrong ways to do it, but common sense will guide you.
My advice:
Start by having the source of this open source code checked into your company's source control system somewhere and capable of being built or re-built as needed. Not necessarily in your project, but just getting the code checked in so it can't be lost or confused with the original author's ever evolving changes on GitHub.
As to how you consume it, you have several options.
Build the open source in it's own project (checked into source control, but separate from your main project). Then just take the drop of compiled files (.class, .jar, .lib, etc...) and check that into your main project. This is the most flexible option if you don't think you are ever going to need to change the open source code that often. Has the side benefit of being managed for several projects.
Drop the source code as-is directly into your project. This means you will always be rebuilding the code. This gives the most flexibility with evolving and changing the the code specific to your project needs.
There's probably hybrid solutions of these options as well.
The bottom line is that whatever you use needs to be copied and building in your own system. Because the code you pulled down from GitHub could go away or change significantly at any time.
A simple solution would be to use JitPack to import those GitHub projects into your gradle build.
First you need to add the repository:
repositories {
maven { url "https://jitpack.io" }
}
and then all the GitHub repositories as dependencies:
dependencies {
compile 'com.github.RepoOwner:Repo:Version'
// more dependencies...
}
Behind the scenes JitPack will check out the code and compile it.
I think you are looking for this. If you are using eclipse, you should check this
If you are looking for adding jar file to your lib, you can simply create a lib folder in your project and add jar file into the library and you must add the line compile files('jarfile.jar') in the build file(gradle build). If you are using eclipse you can follow this
By the way, creating a package for each library and putting all library source codes doesn't look sane to me. It is almost equivalent to recreating the project. I'm sure that it is not the proper approach.
If the third-party code is packaged as a .jar or a .aar and made available in public-facing maven repository (e.g. maven central), then you should add the library as a dependency in your build.gradle file.
If it is not available as a maven/gradle dependency, you could add the library's code to your project as suggested in other answers here. I have never liked that solution at all.
You could also build the .jar or .aar and add that to your project's lib directory, as also suggested by other answers here. For a small, simple project with few dependencies, that might make sense.
What I like to do for larger, longer-lived projects, is to set up my own Nexus server (a Maven repo server), and put the third-party dependencies there.
As you can see from my passed 3 questions I am having major problems with my project setup. I am getting lots of very specific errors that seems like nobody can answer them. I am getting hugely frustrated. So I am going to try a fresh approach. I will describe how I would like my project set up and if somebody could give me some brief steps to follow I would be very grateful. After messing around with this for around a week I believe I have some knowledge but maven seems to be incredibly difficult to understand.
I am writing a library which will be used in 2 projects. The major libraries I would like to use are roboguice, robolectric and jackson(json library). I would like to have a way to test the library but I am unsure if this should be in a different module or not. Robolectric seems to suggest it should be in the same module. I am unsure how I should use this library in the other 2 projects. I have been looking at this http://code.google.com/p/maven-android-plugin/wiki/ApkLib but unfortunately the website tells me next to nothing about how I should create the apklib.
If it is possible I would also like the other 2 projects to have a dependency on that library and build it automatically.
I have been using this site to create the maven project http://stand.spree.de/wiki_details_maven_archetypes
But I have been running into issue after issue. If anybody can point me in the right direction I will be very appreicative
Even if maven is (almost) a foreign country to me, I had some moderate success setting up a maven project and interacting with it using intellij. I wanted to use it because it looked the easiest way to have robolectric working with intellij.
I wrote a blogpost you can find here
What you need is:
Maven android sdk deployer https://github.com/mosabua/maven-android-sdk-deployer
Maven android plugin http://code.google.com/p/maven-android-plugin/wiki/GettingStarted (using android archetypes is just fine)
If you want to build an apk lib instead of an apk, just specify apklib in the packaging tag
PS: I also saw this a while ago, but never gave it a try.
I am having a lot of trouble adding the WEKA library to a project I am working on. I have followed several tutorials that explain how to do this including the Android Developers guide:
http://developer.android.com/guide/appendix/faq/commontasks.html#addexternallibrary
and several of the postings on SO.
I have created a folder in my project with the weka.jar file, created a new library (adding the weka.jar file to the library) and included this library in my build path. I have also added the library under the "Order and Export" tab in the project properties.
I have also tried importing the jar file so that the actual contents of the jar are extracted into a directory in my project.
The end result of all of this is that my project is able to build correctly and without error, but when it comes time to run my code on the emulator I get the following exception:
04-10 22:52:21.051: ERROR/dalvikvm(582): Could not find class 'weka.classifiers.trees.J48', referenced from method edu.usc.student.composure.classifier.GaitClassifierImpl.
with J48 being the class I reference in my code.
Does anyone have any additional suggestions that I may have overlooked?
Thanks!
I just finished my first revision of https://github.com/rjmarsan/Weka-for-Android
Hope it helps!
WEKA is not going to work on Android without changes. J48, for example, requires the java.lang.Cloneable interface, which is not available in Android.
What you need to do is check out the WEKA source code from Subversion, add it to your project (removing the JAR file), compile it, and fix all the compile errors. There may be quite a few of these.