My question is simple, is it possible to create a jar inside a jar in android.
As I have a first.jar file, and I use the methods of the first.jar class in another project class, for example
In first.jar, I have a TestApp1Class class,
public class TestApp1Class { public static void testMethod1(){ Log.i("TEST", "Hi...."); } public static void testMethod2(){ Log.i("TEST", "Hello...."); } }
In another B project, I have a TestApp2Class
class, where I used the methods of the first.jar Class class, such as testMethod1();
as you can see below.
public class TestApp2Class { public static void TestApp2Method() { Log.i("TESTAPP", "Hi TESTAPP2...."); TestAppMethods.testMethod1(); } public static void TestApp2Method2() { Log.i("TESTAPP", "Hello TESTAPP2...."); TestAppMethods.testMethod2(); }
}
This project B I exported as the jar file name of the second.jar file and used this jar in another project C.
how
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TestApp2Class.TestApp2Method(); }
}
And I get an exception in
java.lang.NoClassDefFoundError: com.example.testapp.TestAppMethods
That it cannot access the first.jar class. It bothered me for two days. I think I tried almost everything.
The steps I tried:
- Usually we get this error if it is not marked in order and is not exported. I did this, and also check the box on the dependencies.
- I tried just putting second.jar in the libs folder, not the build path, and tried, and that helped.
- I tried to manually edit the
MANIFEST.IN
file and added one Class-Path: libs/first.jar
and saved the first.jar file in the libs folder when exporting project B to second.jar, and even that did not help. I think that you should not manually edit this MANIFEST.IN file.
These are the things I have tried. Please indicate that I am doing something wrong or that something is missing.
Every time I tried all of the above steps, I got a NoClassDefFoundError
exception.
Logcat:
12-03 18:32:52.119: E/AndroidRuntime(29262): FATAL EXCEPTION: main 12-03 18:32:52.119: E/AndroidRuntime(29262): java.lang.NoClassDefFoundError: com.example.testapp.TestAppMethods 12-03 18:32:52.119: E/AndroidRuntime(29262): at com.example.testapp2.TestaApp2Class.TestApp2Method(TestaApp2Class.java:11) 12-03 18:32:52.119: E/AndroidRuntime(29262): at com.example.jartestapp.MainActivity.onCreate(MainActivity.java:14) 12-03 18:32:52.119: E/AndroidRuntime(29262): at android.app.Activity.performCreate(Activity.java:5133) 12-03 18:32:52.119: E/AndroidRuntime(29262): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 12-03 18:32:52.119: E/AndroidRuntime(29262): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2225) 12-03 18:32:52.119: E/AndroidRuntime(29262): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2311) 12-03 18:32:52.119: E/AndroidRuntime(29262): at android.app.ActivityThread.access$600(ActivityThread.java:149) 12-03 18:32:52.119: E/AndroidRuntime(29262): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293) 12-03 18:32:52.119: E/AndroidRuntime(29262): at android.os.Handler.dispatchMessage(Handler.java:99) 12-03 18:32:52.119: E/AndroidRuntime(29262): at android.os.Looper.loop(Looper.java:137) 12-03 18:32:52.119: E/AndroidRuntime(29262): at android.app.ActivityThread.main(ActivityThread.java:5214) 12-03 18:32:52.119: E/AndroidRuntime(29262): at java.lang.reflect.Method.invokeNative(Native Method) 12-03 18:32:52.119: E/AndroidRuntime(29262): at java.lang.reflect.Method.invoke(Method.java:525) 12-03 18:32:52.119: E/AndroidRuntime(29262): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) 12-03 18:32:52.119: E/AndroidRuntime(29262): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555) 12-03 18:32:52.119: E/AndroidRuntime(29262): at dalvik.system.NativeStart.main(Native Method)