Importing vanilla Java project to use as a library in Android - java

I've written a piece of vanilla Java code to do a specific task. It contains a bunch of packages and resource files.
I want to import the vanilla Java project to Android to use some of its utilities.
I've tried to build my project to jar file, add it to the libs/ folder and import it. I've also tried to import it directly to the project dependencies. However, none of the above worked. The jar file showed up in the "External Library" part, but I cannot import it from a class inside as it gave me compilation error.

HERE you have plenty of ways how to attach jar to Android project
are you shure that your jar (assuming properly built) will work on Android? not all components and classes of "vanilla" Java are available on Googles OS... check out THIS topic for more info

Related

Trouble with a project with imported libraries dependent on other packages

I'm fairly new to Android development and I'm having trouble with external library dependencies at the moment. In particular I've imported a jar file that has upstream dependencies on another package which it can't locate. The package I imported is trying to import java.time.format.SimpleDateTimeTextProvider. I found a jar which apparently contains this package, but when I add it to my project the error still appears. When I try to import the same package into my own source code for the main activity, there are no errors, so it clearly is a standard part of Java and available somewhere on the machine I am working on.
Is there a way to force imported packages to look for packages they are dependant on by searching the rest of the machine? Alternatively, is there another common way of dealing with this? Lastly, does someone know (just in case there is something wrong with the package I've already tried) where I can find a jar file containing java.time.format.SimpleDateTimeTextProvider?
Thanks in advance.

How do I add a Github library to my Android Project as a JAR in Eclipse?

I'm trying to add https://github.com/astuetz/PagerSlidingTabStrip to my project. Looking at it, I notice that it has files in res and depends on its own R.java file. When I make it a JAR I continue to get errors because the dependencies aren't all there. I'm not sure how to get this to work.
I keep getting errors like
import android.support cannot be resolved and everything else too. I tried referencing different answers on StackOverflow but none of them yielded a working solution.
The resources won't be packaged into the JAR file. Google is working on a new packaging scheme called AAR which is supported by Android Studio.
In order to use this third-party library in your own project, you should clone it to a local repo. Then you can import it directly into your Eclipse workspace and then add the Eclipse project to the classpath of your app's project.
Download the whole source code from https://github.com/astuetz/PagerSlidingTabStrip by git tool.
On your Eclipse IDE, import the library as exsisting source code at Android option.
Add the library your add before into your project.

Android+Ant external jar library

I'd like to try org.apache.commons.lang.StringUtils in my Android project. I have downloaded commons-lang3-3.1.jar and placed it in my project's libs directory. However importing it fails with the library not being found. I have used many variations of
import org.apache.commons.lang.StringUtils;
with no success. My environment is the linux console and I'm using ant to compile, no Eclipse. My understanding is that Ant picks up any library in the project libs directory.
Please help. Android/java coding noob.
Lang 3.0 (and subsequent versions) use a different package (org.apache.commons.lang3) than the previous versions (org.apache.commons.lang), allowing it to be used at the same time as an earlier version. ref: http://commons.apache.org/lang/
import org.apache.commons.lang3.StringUtils;
Just put the jars in the libs/ directory. Silly me, I was putting them in the lib/ directory until I ran into the same issue and found the answer here:
How to build an android app with external libraries using ant?

Dependent projects and obfuscation

I'm working on Android code that exists partly in a library project and partly in an app project; the app depends on the library. But the library is obfuscated, so instead of
import com.mycompany.mylibrary.MyClass
I have
import myobfuscatedlib.MyClass
This works fine in production, but I am trying to debug, and I would like to step into the library's methods; I would also like to be able to edit the library classes, then run the app and see my changes. At present the jar that the library file creates is in the app's build path; if I replace the jar with a project reference, all my imports are invalidated. How can I configure my projects to debug the unobfuscated code while obfuscating for the production build?

Adding additional java files to playframework classpath

I have a project that shares models with my android project. I have a separate eclipse project just for models and other shared code. I add this to my play project as a dependency in eclipse.
In eclipse, play compiles and starts without problem. However, I went to deploy to GAE and found that the compilation stage of play's packaging fails because it can't find the models.
I suspect I could hack the ant build files, but that seems brittle.
Is there a standard way to add extra directories to the play compilation source tree or the classpath?
Make a jar-file with your classes and put it in /lib. That's where I put my libraries.
Files in the application /lib folder is automatically added to the class path by Play Framework. See Classpath settings
From Anatomy: "The app directory contains all executable artifacts: Java and Scala source code, templates and compiled assets’ sources" ... and further: "You can of course add your own packages, for example an app/utils package"
You can copy java source files to make a hierarchy of packages under /app, e.g.:
/app/sharedcode/project2/models/domain1 and import that in WhateverController.scala as:
import sharedcode.project2.models.domain1._

Categories