Developing an Ionic/Cordova Plugin - Plugin won't build

I am currently working on a project to develop an android app using Ionic/Cordova. In this app we need to automatically connect to a wifi network using EAP TTLS and to do so we are developing a cordova plugin.

As many tutorials suggest, we started the development by creating an Android app that did exactly what we wanted. Next, we turned it into a plugin. Up to that point everything was great, we achieved the desired functionality and added the plugin to the Ionic project without errors.

Now, when we execute the command ionic build we receive many errors related to the imports used in the plugin, for example:

import android.net.wifi.WifiConfiguration; 
import android.net.wifi.WifiManager; 
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

From all the research done before the development we understood that any app that you could be develop directly for Android could be turn into a plugin. Therefore, I believe that we are missing an important step in the process or taking the wrong approach to the development.

May anyone help me solve this or give me pointers to the proper way to build an Ionic/Cordova plugin?

Here is a copy of the error log:

  ConnectivityChangeReceiver.java:19: error: cannot find symbol
import com.wbinnova.adsfinetworkplugin.R;
                                      ^
  symbol:   class R
  location: package com.wbinnova.adsfinetworkplugin
  ConnectionActivity.java:9: error: package android.support.v7.app does not exist
import android.support.v7.app.ActionBarActivity;
                             ^
  ConnectionActivity.java:17: error: cannot find symbol
public class ConnectionActivity extends ActionBarActivity {
                                        ^
  symbol: class ActionBarActivity
  ScanActivity.java:13: error: package android.support.v7.app does not exist
import android.support.v7.app.ActionBarActivity;
                             ^
  ScanActivity.java:21: error: cannot find symbol
public class ScanActivity extends ActionBarActivity {
                                  ^
  symbol: class ActionBarActivity
  ConnectivityChangeReceiver.java:93: error: package R does not exist
                Notification notification = new Notification(R.mipmap.ic_launcher, "Red Ads-Fi disponible", System.currentTimeMillis());
                                                              ^
  ConnectionActivity.java:24: error: cannot find symbol
        super.onCreate(savedInstanceState);
        ^
  symbol:   variable super
  location: class ConnectionActivity
  ConnectionActivity.java:27: error: cannot find symbol
        wifiManag = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                                  ^
  symbol:   method getSystemService(String)
  location: class ConnectionActivity
  ConnectionActivity.java:53: error: no suitable constructor found for Builder(ConnectionActivity)
        AlertDialog.Builder builder = new AlertDialog.Builder(ConnectionActivity.this);
                                      ^
    constructor Builder.Builder(Context,int) is not applicable
      (actual and formal argument lists differ in length)
    constructor Builder.Builder(Context) is not applicable
      (actual argument ConnectionActivity cannot be converted to Context by method invocation conversion)
  ConnectionActivity.java:22: error: method does not override or implement a method from a supertype
    @Override
    ^
  ConnectionActivity.java:62: error: package R does not exist
        getMenuInflater().inflate(R.menu.menu_main, menu);
                                   ^
  ConnectionActivity.java:62: error: cannot find symbol
        getMenuInflater().inflate(R.menu.menu_main, menu);
        ^
  symbol:   method getMenuInflater()
  location: class ConnectionActivity
  ConnectionActivity.java:59: error: method does not override or implement a method from a supertype
    @Override
    ^
  ConnectionActivity.java:71: error: package R does not exist
        if (id == R.id.action_settings) {
                   ^
  ConnectionActivity.java:75: error: cannot find symbol
        return super.onOptionsItemSelected(item);
               ^
  symbol:   variable super
  location: class ConnectionActivity
  ConnectionActivity.java:66: error: method does not override or implement a method from a supertype
    @Override
    ^
  ScanActivity.java:35: error: cannot find symbol
        super.onCreate(savedInstanceState);
        ^
  symbol:   variable super
  location: class ScanActivity
  ScanActivity.java:36: error: package R does not exist
        setContentView(R.layout.activity_main);
                        ^
  ScanActivity.java:39: error: cannot find symbol
        mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                                 ^
  symbol:   method getSystemService(String)
  location: class ScanActivity
  ScanActivity.java:33: error: method does not override or implement a method from a supertype
    @Override
    ^
  ScanActivity.java:54: error: package R does not exist
        getMenuInflater().inflate(R.menu.menu_main, menu);
                                   ^
  ScanActivity.java:54: error: cannot find symbol
        getMenuInflater().inflate(R.menu.menu_main, menu);
        ^
  symbol:   method getMenuInflater()
  location: class ScanActivity
  ScanActivity.java:51: error: method does not override or implement a method from a supertype
    @Override
    ^
  ScanActivity.java:63: error: package R does not exist
        if (id == R.id.action_settings) {
                   ^
  ScanActivity.java:67: error: cannot find symbol
        return super.onOptionsItemSelected(item);
               ^
  symbol:   variable super
  location: class ScanActivity
  ScanActivity.java:58: error: method does not override or implement a method from a supertype
    @Override
    ^
  ScanActivity.java:74: error: cannot find symbol
        mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                                 ^
  symbol:   method getSystemService(String)
  location: class ScanActivity
  ScanActivity.java:99: error: cannot find symbol
        WifiManager wifiManag = (WifiManager) getSystemService(Context.WIFI_SERVICE);
                                              ^
  symbol:   method getSystemService(String)
  location: class ScanActivity
  ScanActivity.java:153: error: cannot find symbol
            Intent intent2 = new Intent(ScanActivity.this, ConectionActivity.class);
                                                           ^
  symbol:   class ConectionActivity
  location: class ScanActivity
  ScanActivity.java:154: error: cannot find symbol
            startActivity(intent2);
            ^
  symbol:   method startActivity(Intent)
  location: class ScanActivity

You should include the missing libraries, in a build-extras.gradle file. And also include a reference on plugin.xml.

build-extras.gradle:

repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
mavenCentral()
jcenter()
}

dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:22.2.1'
//your dependencies.
}

plugin.xml
<framework src="build-extras.gradle" custom="true" type="gradleReference" />

1 Like

any news? i face the same problem

Hey @caat91 Can you please let us know how to build or develop a new plugin, or please share some link from where I can get the info…

This might not be much help but after we struggled with this a member of the team patiently checked all the documentation and found a solution for our problem. This is the StackOverflow’s post, I hope it helps you out a bit.

1 Like