title: Can't start an activity from a cordova plugin using .aar files
body: <p>I am trying to write a simple cordova-plugin for android, but I am stuck into a crash that I don't know how to resolve.</p>
  
  <p>I basically followed these steps to create simple plugin and it worked fine.</p>
  
  <p><a href="http://www.mat-d.com/site/tutorial-creating-a-cordova-phonegap-plugin-for-android-app/" rel="nofollow noreferrer">http://www.mat-d.com/site/tutorial-creating-a-cordova-phonegap-plugin-for-android-app/</a></p>
  
  <p>Yet, my plugin must call an activity that is packaged as an .aar file. Basically I have a full blown application with java/layouts that needs to be triggered by the plugin.</p>
  
  <p>I followed these steps to add my .aar file to the android build of cordova.</p>
  
  <p><a href="https://stackoverflow.com/questions/30757208/cordova-plugin-development-adding-aar">Cordova plugin development - adding aar</a></p>
  
  <p>It also worked. Now, I have so far in my plugin structure these files (admittedly is pretty hacked right now since I kept most of original names):</p>
  
  <p><a href="https://i.stack.imgur.com/1bVlv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1bVlv.png" alt="enter image description here"></a></p>
  
  <p>in my yourFile.gradle I have this:</p>
  
  <pre><code>repositories{    
    jcenter()
    flatDir{
        dirs 'libs'
     }
  }
  
  dependencies {
     compile(name:'mylittlelibrary-release', ext:'aar')
     compile 'com.android.volley:volley:1.0.0'
  }
  
  android {
    packagingOptions {
      exclude 'META-INF/NOTICE'
      exclude 'META-INF/LICENSE'
    }
  }
  </code></pre>
  
  <p>and the main part of my "CoolPlugin.java" looks like this:</p>
  
  <pre><code>public class CoolPlugin extends CordovaPlugin {
      public CoolPlugin() {}
      public void initialize(CordovaInterface cordova, CordovaWebView webView) {
          super.initialize(cordova, webView);
      }
      public boolean execute(final String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
          cordova.getActivity().runOnUiThread(new Runnable() {
              public void run() {
                  final Context context = cordova.getActivity().getApplicationContext();
                  try {
                      Intent intent = new Intent(context, testv.com.mylittlelibrary.MainActivity.class);
                      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                      cordova.getActivity().startActivity(intent);
                  } catch (Exception e) {
                      String errorText = e.toString();
                      Toast toast = Toast.makeText(context, errorText, duration);
                      toast.show();
                  }
  </code></pre>
  
  <p>My "mylittlelibrary-release.aar" has its main activity under the namespace "testv.com.mylittlelibrary" so the MainActivity.java looks like this:</p>
  
  <pre><code>package testv.com.mylittlelibrary;
  
  import android.content.Context;
  import android.support.v7.app.AppCompatActivity;
  
  import com.android.volley.*;
  import com.android.volley.toolbox.*;
  
  public class MainActivity extends AppCompatActivity {
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          etc...
  </code></pre>
  
  <p>I was reading the thread below, and looks like I need in somehow register the main activity of my aar file.</p>
  
  <p><a href="https://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin">open an activity from a CordovaPlugin</a></p>
  
  <p>I am not totally sure how to do this, so I went inside the auto-generated AndroidManifest.xml under</p>
  
  <p>C:\cordova\hello\platforms\android\AndroidManifest.xml</p>
  
  <p>and hacked the activity with the namespace inside as such:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.example.hello" xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true"&gt;
          &lt;activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize"&gt;
              &lt;intent-filter android:label="@string/launcher_name"&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:label="@string/activity_name"
          android:launchMode="singleTop"
          android:name="testv.com.mylittlelibrary.MainActivity"&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
      &lt;uses-sdk android:minSdkVersion="17" android:targetSdkVersion="23" /&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I installed the plugin and ran the app using:</p>
  
  <pre><code>cordova plugin add c:/CoolPlugin/
  cordova build android
  cordova run android
  </code></pre>
  
  <p>there is button in the html file that triggers the plugin, which then triggers my activity as you see on the "MainActivity" of the "mylittlelibrary-release.aar" file.</p>
  
  <p>Yet, I keep getting this crash. I believe the android plugin cannot resolve the namespace properly and throws this exception.</p>
  
  <pre><code>com.example.hello E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.hello, PID: 13119
      java.lang.NoClassDefFoundError: Failed resolution of: Ltestv/com/mylittlelibrary/MainActivity;
      at CoolPlugin$1.run(CoolPlugin.java:59)
      at android.os.Handler.handleCallback(Handler.java:739)
      at android.os.Handler.dispatchMessage(Handler.java:95)
      at android.os.Looper.loop(Looper.java:145)
      at android.app.ActivityThread.main(ActivityThread.java:5835)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:372)
  </code></pre>
  
  <p>I also believe is has something to do with the proper registering the MainActivity under the testv.com.mylittlelibrary. But I can't figure out how to do in in cordova. I need to resolve this, so I am glad to give you points of my reputation for a solid answer that unblocks me.</p>
  
  <p>thank you.</p>