开发Ionic / Cordova插件 - 插件不会构建

时间:2015-08-23 14:57:43

标签: android cordova plugins ionic-framework cordova-plugins

我目前正在开发一个使用Ionic/Cordova开发Android应用的项目。在这个应用程序中,我们需要使用EAP TTLS自动连接到wifi网络,为此我们正在开发一个cordova插件。

正如许多教程所示,我们通过创建一个完全符合我们想要的Android应用程序来开始开发。接下来,我们将其变成了一个插件。到目前为止,一切都很棒,我们实现了所需的功能,并将插件添加到Ionic项目中,没有错误。

现在,当我们执行命令ionic build时,我们会收到许多与插件中使用的导入相关的错误,例如:

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;

从开发之前完成的所有研究中我们了解到,您可以直接为Android开发的任何应用都可以变成插件。因此,我认为我们错过了这个过程中的重要一步,或者采取了错误的方法来开发。

愿任何人帮我解决这个问题或者指出构建Ionic / Cordova插件的正确方法吗?

以下是错误日志的副本:

  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

1 个答案:

答案 0 :(得分:1)

看来你正在创建一个Java动作,你需要创建一个简单的Java类,其中包含一些函数,允许你将该Java类转换为cordova的插件

在这里你可以找到如何创建一个简单的echo插件:

https://cordova.apache.org/docs/en/2.5.0/guide/plugin-development/android/

注意它扩展CordovaPlugIn,主函数是execute,带有3个参数

  • 将要执行的操作的名称。字符串参数
  • 论点。 JSONArray参数
  • 回调。这将在函数结束时调用,如果要返回值,则将其作为函数成功或错误的参数传递