Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid library project as jar file for distribution, like google analytics
    primarykey
    data
    text
    <p>I have seen <a href="https://stackoverflow.com/questions/5014128/create-an-android-jar-library-for-distribution">this</a> question, and have some more doubts regarding creating a jar file which I can distribute and can be used in any android applications.</p> <p>What my requirement is </p> <ol> <li>As I said, I want to build and distribute a closed source library. I don't want the source code to be visible.</li> <li>In that library I don't want to use any assets, layouts, resources etc. But I want to use some android specific codes, like <a href="https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id">getting android device id.</a></li> </ol> <p>The most popular answer in the above linked SO question tells to <strong>create a regular java project and import android.jar in it.</strong> I tried to do that, but I don't know how to add android.jar to any java project. I would like to get some clarification on that too.</p> <p>Moreover I would like to know if there are any other methods using android sdk itself (without using java project) create a closed source library jar file. </p> <p>I think what I want is possible, since <a href="https://developers.google.com/analytics/devguides/collection/android/" rel="nofollow noreferrer">google analytics for android native apps</a> seems to have done it. I am sure in the .jar file they distribute they are using android specific codes, since there seems no other way for them to get the device information to display in the analytics viewer. </p> <h1>EDIT : CAN SOMEONE CLARIFY THIS??</h1> <p>I think I have made some progress. This is what I have done</p> <ul> <li><p>Created a regular android project (not library project, the "is Library" checkmark is unchecked)</p></li> <li><p>In the project I have coded out my logic. It uses some android specific classes like <code>SharedPreference</code>, <code>UUID</code>, <code>PackageManager</code>. But nothing related with assets, layouts also no class extending <code>Activity</code>. Just a java class extending <code>java.lang.object</code></p></li> <li>Exported the project using <strong>Project->rightclick->export->Java->JAR file</strong>. In the next screen I unchecked the checkbox near <code>AndroidManifest.xml</code>. Set a destination directory to export and clicked next thrice with keeping the default settings. Then I clicked Finish, and got a lovely <strong>libMyLibraryName.jar</strong> at my desktop.</li> </ul> <p>Then I created another android project, added this <code>libMyLibraryName.jar</code> to new project using <strong>project->rightclick->properties->java build path -> libraries->add external jar.</strong></p> <p>And I tried to use my class in the library, in my new project</p> <pre><code>MyLibraryClass objClass = new MyLibraryClass(this); </code></pre> <p>And I was able to compile and run successfully. I even sent the library to one of my co worker who was able to use the library in his on machine (Just making sure library project in my workspace wont influence the project using it). </p> <p>Now I have 2 questions.</p> <p><strong>1) My first question is , what they meant by the term "true library" in the below given documentation ?</strong> Is it any non android java project which can be exported to a JAR file?</p> <blockquote> <p>However, a <strong>library project</strong> differs from an standard Android application project in that you cannot compile it directly to its own .apk and run it on an Android device. <strong>Similarly, you cannot export the library project to a self-contained JAR file</strong>, as you would do for a <strong>true library</strong>. Instead, you must compile the library indirectly, by referencing the library in the dependent application and building that application.</p> </blockquote> <p>Well this portion is taken from <a href="http://developer.android.com/guide/developing/projects/index.html" rel="nofollow noreferrer">documentation</a> under title "Library Projects".</p> <p><strong>2) My second question is, anything wrong with the way I have created the JAR file?</strong> Any possible pitfalls which might bite me back later? I would like to make sure I am not doing something terribly wrong, before using it in my important projects. </p> <p>I might add that I didn't try the method of creating a JAVA project and importing <code>android.jar</code>. I am ready to try that one, if what I have done currently is wrong.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload