Android Library Project without sources - java

I've created Android Library Project which depends on three libraries : google-play-services_lib, android-support-v7-library and pull-to-refresh ( https://github.com/chrisbanes/Android-PullToRefresh/blob/master/library/src/com/handmark/pulltorefresh/library/PullToRefreshBase.java )
I marked my project as library and want to create jar which can be used as jars are used is google_play_services and android-support library. My question is what I have to do to be sure that libraries that my project depends on are not included in my jar. I want 3rd person - who will use my library - to add them with my projectes as dependencies and get it work.
Unchecked export options in java build path is enough?

I don't know exactly if you have used Gradle or not. But if it's the former, then you don't have to do nothing. If you have include your dependencies in your library project like this:
dependencies {
compile 'whatever:library'
}
Then it's ok.
Note: If your project includes resources (like layouts and more) it can not be compiled as a jar!
Note2: If you didn't use Gradle, notify me in the comment and I'll update this post explaining how to achieve that.
UPDATE 1:
First of all, let me link you to another related answer I did the last week. It gives you useful links to learn Gradle in a hurry (at least all the basics).
Second, do you use Android Studio?
UPDATE 2:
It's just a matter of taste ;)! But with Android Studio (Intellij) you don't need to configure the extra step to get Gradle working.
Well, after you have read those links I've put before, the next step is to create a library project (in Android Studio it will generate the required folders/files automatically for you).
In your lib or library folder (where you put your source code of your library) in your build.gradle put the following:
dependencies {
compile 'com.google.android.gms:play-services:4.4.52'
compile 'com.android.support:gridlayout-v7:19.1.0'
compile 'it.sephiroth.android.library.fork.actionbarpulltorefresh:actionbarpulltorefresh:0.9.92'
}
And with that you can generate your library in aar format.
NOTE: Android-PullToRefresh library is not Gradelized, so I had to search for another alternative that has been uploaded to MavenCentral (like sephiroth's one). Remember to use Gradle, please! To search already Gradelized libs!

Related

Android Studio java module dependancy from local directory

I have a question regarding whether module dependencies in a java app built in Android studio can be sourced from a local directory instead of an online repository. The code in question is in build.gradle and looks like this:
dependencies {
implementation 'org.hibernate:hibernate-core:3.6.7.Final'
}
This will pull files from a repository into the project at build time. But say I would like to download the dependency (say, from GitHub) and store it locally on my file system and include it into the project from there. How would this be done?
I've tried the following:
dependencies {
implementation '~/path/to/files/'
}
But I get the error Supplied String module notation '~/path/to/files/' is invalid. Example notations: 'org.gradle:gradle-core:2.2', 'org.mockito:mockito-core:1.9.5:javadoc'. (where ~/path/to/files/ is a real path)
The reason I ask is because I'd like to use a library in my project and include it as a dependency. The library is on GitHub. But I'd like to make some changes to it before it's imported. The only solution I can think of is to download it, make the changes and then uploaded as my own forked library back to GitHub again and it include that. But if I can somehow just work on it locally, I'd prefer that. Any ideas?

How do I easily include Google's GCS package into my code?

I want to use the Google Cloud Storage from Java in App Engine. The documentation on how to install this is very thin. I found the source code for com.google.appengine.tools.cloudstorage but when this source is put into the build path (Eclipse) it generates lots of compile errors. I then track down those sources, add them in and then get more compile errors from more dependencies. It seems like I am missing something about how to use this code in a much simpler way.
You can generate the library jar and also get its dependencies using Java Ant and the direction mentioned here or better yet, use maven and include appengine-gcs-client as a dependency.
If you don't use Maven, right-click on your project > Google > Add Google APIs > Cloud Storage JSON API.
This will add all the dependencies that you need. After that, the only jar you need is appengine-gcs-client.

Starting work with FXyz library

Have problem with adding the library to the environment, mean after i included two jar files to the project : JCSG.jar, poly2tri.jar it steal doesn't work,
do I have to do something else ?
To compile this project, I would recommend the version from https://github.com/FXyz/FXyz which comes with updated Gradle dependencies, i.e., dependencies are downloaded automatically. No need to manually download dependencies.

What is the proper Gradle project structure for switching between 'project' and 'external' dependencies

I have this small set of libraries and app:
forge-base - java project (Intellij IDEA project)
forge-android - android library project, depends on forge-base (AS project)
forge-android-skeleton - sample android app, depends on forge-android (AS project)
During the initial development I used structure with project dependencies like:
settings.gradle:
...
include ':forge-base'
project(':forge-base').projectDir=new File("$settingsDir/../forge/base")
...
and then in build.gradle:
compile project(':forge-base')
This worked like a charm but later I needed to publish the libs on maven repo and dependencies had to be changed like:
build.gradle:
compile 'com.bolyartech.forge:forge-base:2.0-SNAPSHOT'
The problem that I am facing now is that I am trying to do some major refactoring in all the 3 projects and I need the old deps structure in order easily to confirm the consistency of the projects, e.g. to build just the skeleton app and all the recursive recompile/building to take place automatically (as it does when a lib project is referenced with compile project(':forge-base')). If I use the 'new' structure with publishing to the (local) maven I have to publish the lib each time (with incremented version) I change something in it in order changes to be visible by the other two projects.
What (is there) is the usual/canonical why to handle situations like this?
Is there an easy way to switch between the two 'modes', e.g. 'internal' / 'external' dependencies?
It turns out it is pretty easy to do it. You can use different dependencies for the different build types, i.e. debug/release so for example for my forge-android-skeleton project now I have the following:
in settings.gradle:
include ':app'
include ':forge-base' project(':forge-base').projectDir=new
File("$settingsDir/../../../forge/base")
include ':forge-android' project(':forge-android').projectDir=new
File("$settingsDir/../../../forge-android/forge-android")
in app/build.gradle:
...
releaseCompile ('com.bolyartech.forge:forge-android:2.7-SNAPSHOT')
debugCompile project(':forge-android')
...
Please note that in the settings.gradle you need to have all the dependencies back to the bottom otherwise it will not work (that is the reason forge-base is defined there even not excplicitly used).
You can also define yet another build type like direct-deps and use it in case you don't like to mess with debug/release types.
Please note that in case you are using different IDEs for some of the projects (like in my case IDEA and AS) probably it will be good idea to ensure that both are using same (version of) gradle otherwise unexpected problems may occur.

Dalvik VM error: Exception found "Javax.xml.namespace.QName.class"

This isn't intended to be a question. Rather, an observation which is a common problem found in Android when you use external APIs for development and android.jar isn't duplicated into your project!
After searching through various forums, Google and stackoverflow, I seem to get a solution by myself and thought of sharing it.
Whenever you are linking external libraries, better link it by creating a /lib folder and dump those .jars there(means to COPY the files and NOT linking them). Link them using Eclipse -> Build Properties -> Configure Build path -> Library tab -> Add external Jars. Add the required .jars saved in /lib folder in this. (Note that, the jar included as a "Referenced Library" in Eclipse will disappear in /lib folder! But, not to worry as proper linking has happened. Another note is to check that the /lib jar that was referenced should NOT be visible in Libraries tab of Build Properties as it will be inherited.)
Another major problem was when Google APIs are being used. Specially the ones, which use some core library functions of java/javax. Be very careful of this. The error is that, the DalvikVM tries to link these but fails as there is a duplication found and is unable to decide which one to refer to. Below is the error.
Dx trouble processing "javax/xml/namespace/QName.class":
Ill-advised or mistaken usage of a core class (java.* or javax.*) when not building a core library.
In such cases, what I have observed is that, this class is used in xpp3-1.1.4c.jar. If you've copied this into your /lib folder, PLEASE REMOVE IT. Then clean the project, and give a fresh build. And the ship sails smoothly thereafter.
Do this for other referenced .jars if such duplication exists.
Cheers!
This worked for me. I'm using maven, and the xpp3-1.1.4c dependency shows up under "Maven Dependencies"; I had to exclude it using (right click the dependency) Maven-> "Exclude Maven Artifact...". Thanks a bunch -- this was really obscure.
This error show only when you trying to generate signed APK.
There are 2 ways to fix this.
1. As commented Amira Elsayed Ismail in this post this
we should revert to gradle 2.3.3.
To do this you should also download Android Studio 2.3.3 because studio 3.0.1 require gradle plugin 3.0+
This was the first solution. But reverting Android Studio and gradle plugins is a painful solution.
2. Resolve all dependency conflicts.
When i revert gradle, Studio 2.3.3 showed we interested warnings(i do not know why studio 3.0.1 don't show dependency conflict warnings)
Warning:WARNING: Dependency xpp3:xpp3:1.1.4c is ignored for debug as it may be conflicting with the internal version provided by Android.
Warning:WARNING: Dependency org.apache.httpcomponents:httpclient:4.3.3 is ignored for debug as it may be conflicting with the internal version provided by Android.
So these dependencies are ignored for debug but NOT FOR RELEASE.
I fixed this by excluding these dependencies.
configurations {
all*.exclude group: 'xpp3', module: ['xpp3' ,'httpclient']
}
After this, i successfully generated signed APK using gradle 3.0.1.(without reverting).

Categories