title: How to keep a jar file external but still use its classes in my Android project?
body: <p>I need to have a jar file located in a main/assets directory within an Android project. It is important the jar file is located there.</p>
  
  <p>With my main Android project is there a way to reference this jar file in my code and to use its classes?</p>
  
  <p>To be clear I don't want to add the jar to the main project once compiled.</p>
  
  <p><strong>EDIT</strong>: I have tried the link below and it seems to load the Class file I've stated. But I'm strugging how to define constructor arguments for the dynamically loaded Class.</p>
  
  <p><strong><a href="http://android-custom-class-loading-sample.googlecode.com/svn/trunk/android-custom-class-loading-sample/src/com/example/dex/" rel="noreferrer">android-custom-class-loading-sample</a></strong></p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>Nearly there. I've confirmed the class is loaded from my classes.jar. I'm stuck instantiating it though.</p>
  
  <p>On the licenseValidatorClazz.getConstructor line I get the error below. I'm guessing I'm missing something from my Interface file?</p>
  
  <p>java.lang.NoSuchMethodException:  [interface com.google.android.vending.licensing.Policy, interface com.google.android.vending.licensing.DeviceLimiter, interface com.google.android.vending.licensing.LicenseCheckerCallback, int, class java.lang.String, class java.lang.String]</p>
  
  <pre><code>    public Class licenseValidatorClazz = null;
      public LicenseValidator validator;
  
      ...
  
      // Initialize the class loader with the secondary dex file.
      DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(),
      optimizedDexOutputPath.getAbsolutePath(),
      null,
      mContext.getClassLoader());
  
          try {
              // Load the library class from the class loader.
              licenseValidatorClazz = cl.loadClass("com.google.android.vending.licensing.LicenseValidator");
  
              validator = (LicenseValidator) licenseValidatorClazz.getConstructor(Policy.class,DeviceLimiter.class,LicenseCheckerCallback.class,int.class,String.class,String.class).newInstance(ddd, new NullDeviceLimiter(),
                      callback, generateNonce(), mPackageName, mVersionCode);
  
          } catch (Exception exception) {
              // Handle exception gracefully here.
              exception.printStackTrace();
          }
  </code></pre>
  
  <p>I have an Interface which contains the functions to pass to the loaded class.</p>
  
  <pre><code>public interface LicenseValidator
  {
      public LicenseCheckerCallback getCallback();
      public int getNonce();
      public String getPackageName();
      public void verify(PublicKey publicKey, int responseCode, String signedData, String signature);
      public void handleResponse(int response, ResponseData rawData);
      public void handleApplicationError(int code);
      public void handleInvalidResponse();
  }
  </code></pre>