2

I read a lot about this issue but I still can´t do it work.

I have two projects: one does some stuff and what I want to do is set it as jar file and use it in the main project, call it and take the info I don´t know how to instanciate a class of that package to start with the process. The secondary project works fine alone and I want to take the info and use it in the main project. If I set the secondary as Library and add it to the main it works fine but I don´t want to do it in this way.

I think it´s possible to do it but I don´t know how to instantiate a class from a jar file and I´m starting to be desperate.


this is the logCat when I call the activity in the jared

file 03-22 11:04:57.900: E/AndroidRuntime(11895): FATAL EXCEPTION: main
03-22 11:04:57.900: E/AndroidRuntime(11895): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.suscribir/com.example.suscribir.Suscribir}; have you declared this activity in your AndroidManifest.xml?
03-22 11:04:57.900: E/AndroidRuntime(11895):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at android.app.Activity.startActivityForResult(Activity.java:2827)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at android.app.Activity.startActivity(Activity.java:2933)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at com.example.principal.Principal$1.onClick(Principal.java:37)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at android.view.View.performClick(View.java:2485)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at android.view.View$PerformClick.run(View.java:9080)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at android.os.Handler.handleCallback(Handler.java:587)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at android.os.Looper.loop(Looper.java:130)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at android.app.ActivityThread.main(ActivityThread.java:3687)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at java.lang.reflect.Method.invokeNative(Native Method)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at java.lang.reflect.Method.invoke(Method.java:507)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
03-22 11:04:57.900: E/AndroidRuntime(11895):    at dalvik.system.NativeStart.main(Native Method)

this is how I call the Activity with an intent

intent.setAction(Intent.ACTION_MAIN);
                intent.setClassName("com.example.suscribir", "com.example.suscribir.Suscribir");
                startActivity(intent);

this is the Manifest

<activity
    android:name="com.example.suscribir.Suscribir">
</activity>

If you need more info, just tell me Thanks again

2 Answers 2

1

http://androiddevelopement.blogspot.in/2011/01/creating-jar-file-in-eclipse.html. Creating jar from eclipse

Cannot package resources, manifest entries. Pure Java code (perhaps using Android APIs), can be packaged into jars.

To use it , just copy the jar to your libs folder under the project.

Right click on project. Goto Properties. Java Build Path. Click Add Jars. Add jar from your libs folder.

After that you can use import statement and instantiate it in your new project class.

7
  • Thanks Raghunandan, I followed that tuto before. I can´t use res folder in the library?? how can I use Buttons, EditText, TextView...??
    – Ivan
    Commented Mar 21, 2013 at 20:43
  • you have to define the ui elements again in your second project. Commented Mar 22, 2013 at 6:31
  • you cannot use res folder in library. Commented Mar 22, 2013 at 6:49
  • OK Raghunandan, I have to redefine the ui elements in the main project , so I have them duplicated in the jar file and in the main project instead of I have to use which are in the main project. Is it OK?
    – Ivan
    Commented Mar 22, 2013 at 8:01
  • you can have java files jared. Use those jars in your project. Instead of writing classes again you will reusing the class files. But your ui for each project have to be redefined. Your jar file will not have have resource files so there is no question of having ui elements duplicates. Commented Mar 22, 2013 at 8:05
0

I'm not completely sure if I understand your question right. You have two Android applications that use the same classes? Is that right? You need to extract the common classes into a Library project in that case. I don't think that you can reference one Android Application project from another.

1
  • You understood it, I have commom classes I want to use by others, for that I want to create a jar file with that classes and use them from other projects, I know how to export the project as jar file and how to import a jar file but I don´t know how to use that classes
    – Ivan
    Commented Mar 21, 2013 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.