Coder Social home page Coder Social logo

dpa99c / cordova-plugin-hello-c Goto Github PK

View Code? Open in Web Editor NEW

This project forked from clement360/cordova-hello-jni-plugin

40.0 6.0 24.0 342 KB

A simple example of a cross-platform Cordova plugin for Android & iOS that uses C code.

License: Apache License 2.0

Java 18.19% Makefile 10.38% C 35.63% Objective-C 15.11% JavaScript 4.43% Batchfile 0.45% Shell 14.70% C++ 1.12%

cordova-plugin-hello-c's People

Contributors

angelskieglazki avatar clement360 avatar dflourusso avatar domq avatar don avatar dpa99c avatar edewit avatar jamesingham avatar kellycampbell avatar luisdemarchi avatar marceloboth avatar partus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-hello-c's Issues

How can I use structs?

Hi,

I'm trying to use my C code and works fine, but when I have to call a function that takes Structs as input and/or output, I don't know how to send the information in JS. Example:

** .h File **

struct input_example {
    struct other_struct othStruct;
    struct internal_struct internalStruct;
    struct stores_external_Struct externalStruct[3];
    char path[200];
    char file [20];
    char database[200];
    int id;
};
struct output_example {
    int id;
    char somechar[100];
    int limitIntegers[15];
    float somefloat;
};

** .C File **

#include "file.h"
long calc_example(struct input_example *input, struct output_example *output)
{
 .... all code ....
}

** ..js File **

/*global cordova, module*/
module.exports = {
    calc_example: function(STRUCT ,successCallback, errorCallback) {
        cordova.exec(successCallback, errorCallback, "HelloCPlugin", "calc_example", [STRUCT]);
    },

How to call a function with input sctructs directly from JS file?

I don't know how to pass parameters as struct values in JS file. May be as an Array, multi-array?

Thank you!

Failed to restore plugin

Hello, after downloading the test-project and executing "cordova platform add android" I get this Error.

screenshot 1

Any idea how to fix this?

thx

Error initializing Cordova: Class not found

When I run my Ionic project with this plugin, after the launch on the device appears an alert that says:

Error initializing Cordova: Class not found

How can i fix this problem?

Class Not Found

I downloaded the plugin and run it on the test project. However, when I run it on my emulator I had class not found ! (and I hadn't changed the C code yet!)
android version: 8.0.0
Cordova version: 9.0.0 ([email protected])
Capture

Help Needed

How do we include custom CFLAGS in the below makefile

SRC=$(wildcard $(SRC_PATH)/*.c)
OBJS=$(patsubst %.c,%.o,$(SRC))

LDLIBS=$(patsubst %, $(TARGET_PATH)/lib%.a, $(DEPS))

all:$(ARCH)-$(LIBNAME).a

$(ARCH)-$(LIBNAME).a: $(OBJS)
@echo $(LDLIBS) $(OBJS)
$(AR) rcs $@ $(OBJS)
ranlib $@

clean:
rm $(OBJS)

.PHONY: realclean
realclean: clean
rm *.a

Android.mk not found

Hello,

now i get this error while trying to "cordova platform add android".
screenshot 6

have you changed something?

compile-android.cmd error

Hello, when I execute the "compile-android.cmd" i get the following error.
screenshot 5
Would be great if somebody could help me.

cordova platform 7.x problems

hello,
I'm trying to make the test project work (cordova-plugin-hello-c) with [email protected] but I get this error:

cordova run android
cp: copyFileSync: could not write to dest file (code=ENOENT):/home/xxx/workspace/cordova-wrapper-c/platforms/android/res/xml/config.xml

Error: Unhandled error. (Parsing /home/xxx/workspace/cordova-wrapper-c/platforms/android/res/xml/config.xml failed)

I think the problem is that this plugin does not support [email protected]. How can I integrate it into my project with [email protected]?

Processing Raw Data in C

Hi Dave,

I have been looking at your example of a cordova compiler for C via a Cordova plugin. This is new territory for me so please bear with my ignorance on this subject.

I have a question that I hope you might be able to answer: I have a unique challenge in that I want to process some raw data received on my phone via bluetooth, but the processing algorithm is written in C. Based on your example, I'm not sure whether it is possible to do this without somehow importing the data directly into the C code.

Am I mistaken? Would it be possible to import the raw data into my Ionic app and have it processed by something similar to your plugin and then have the output available to my app?

My thanks in advance.

Help C++

So, how can i send strings from JS to JAVA and JAVA to C++ Libraries. The C++ libraries too return the strings to JS to answer the user ?

Because the files do not work.

To send the strings from JS :
loadfileae.myLoad("string1", "string2", "string3", function(msg){
alert(msg);

},function(err){
alert(err);
});

Plugin JS :
module.exports = {
myLoad: function (setData1,setData2,setData3, successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "LoadFileAe", "myLoad", [setData1, setData2, setData3]);
}
};

JAVA 1 :
package com.ae.plugin;

import org.apache.cordova.*;
import org.json.JSONArray;
import org.json.JSONException;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class LoadFileAe extends CordovaPlugin {

protected static final String TAG = "LoadFile Plugin";
protected CallbackContext context;

@OverRide
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
context = callbackContext;
boolean result = true;

try {
if (action.equals("myLoad")) {
String setData1 = data.getString(0);
String setData2 = data.getString(1);
String setData3 = data.getString(2);
String jniOutput = LoadFileAeJni.stringFromJNI(setData1, setData2, setData3);
String output = jniOutput;
callbackContext.success(output);

}else{
handleError("Invalid loader file !");
result = false;
}
} catch (Exception e) {
handleException(e);
result = false;
}
return result;
}

private void handleError(String errorMsg) {
try {
Log.e(TAG, errorMsg);
context.error(errorMsg);
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}

private void handleException(Exception exception) {
handleError(exception.toString());
}

}

JAVA 2 :
package com.ae.plugin;

import android.app.Activity;
import android.widget.TextView;
import android.os.Bundle;

public class LoadFileAeJni {

public static native String stringFromJNI(String setData1, String setData2, String setData3);
static {
System.loadLibrary("loadfileae-jni");
}
}

C++ :
#include <string.h>
#include <jni.h>

using namespace std;

JNIEXPORT jstring JNICALL Java_com_ae_plugin_LoadFileAeJni_stringFromJNI
(JNIEnv *env,jobject thisObj, jstring getData1, jstring getData2, jstring getData3){

const char *fichier = env->GetStringUTFChars(getData1, NULL);
const char *uuid = env->GetStringUTFChars(getData2, NULL);
const string *extention = env->GetStringUTFChars(getData3, NULL);

if (fichier == NULL){
fichier="Aucun fichier detecté !";
}
if (uuid == NULL){
uuid="Aucune clé detecté !";
}
if (extention == NULL){
extention="Aucune extention detecté !";
}

env->ReleaseStringUTFChars(getData1, fichier);
env->ReleaseStringUTFChars(getData2, uuid);
env->ReleaseStringUTFChars(getData3, extention);

char resultat[999];
cout << "K7Player C++ Response : " << fichier << "Uuid : " << uuid << "Extention : " << extention << endl;
cin >> resultat;

return env->NewStringUTF(resultat.c_str());
}

iOS 10 is the maximum deployment target for 32-bit targets

Hi,

I'm getting this error every time I run ./compile-ios:
clang: error: invalid iOS deployment version '-miphoneos-version-min=13.5', iOS 10 is the maximum deployment target for 32-bit targets [-Winvalid-ios-deployment-target]

Do you any idea?

compile-android problem

Hello,
I'm editing the files .c and .h in the /src/common/ but when I go to run compile-android it just generates the .so for arm64-v8a, armeabi-v7a, x86 and x86_64 architectures, omitting armeabi, mips and mips64.
This is the output:

./compile-android
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-14.
[arm64-v8a] Compile : helloc <= hello.c
[arm64-v8a] Compile : helloc <= mycomponent.c
[arm64-v8a] Compile : helloc <= mylib.c
[arm64-v8a] Compile : helloc <= mypart.c
[arm64-v8a] SharedLibrary : libhelloc.so
[arm64-v8a] Install : libhelloc.so => libs/arm64-v8a/libhelloc.so
[armeabi-v7a] Compile thumb : helloc <= hello.c
[armeabi-v7a] Compile thumb : helloc <= mycomponent.c
[armeabi-v7a] Compile thumb : helloc <= mylib.c
[armeabi-v7a] Compile thumb : helloc <= mypart.c
[armeabi-v7a] SharedLibrary : libhelloc.so
[armeabi-v7a] Install : libhelloc.so => libs/armeabi-v7a/libhelloc.so
[x86] Compile : helloc <= hello.c
[x86] Compile : helloc <= mycomponent.c
[x86] Compile : helloc <= mylib.c
[x86] Compile : helloc <= mypart.c
[x86] SharedLibrary : libhelloc.so
[x86] Install : libhelloc.so => libs/x86/libhelloc.so
[x86_64] Compile : helloc <= hello.c
[x86_64] Compile : helloc <= mycomponent.c
[x86_64] Compile : helloc <= mylib.c
[x86_64] Compile : helloc <= mypart.c
[x86_64] SharedLibrary : libhelloc.so
[x86_64] Install : libhelloc.so => libs/x86_64/libhelloc.so

Once the lib.so is generated, I remove the android platform, re-add it and I get this error back

workspace/cordova-plugin-hello-c-test/plugins/cordova-plugin-hello-c/src/android/libs/armeabi/libhelloc.so" not found!

How do I generate the missing architectures? is my flow wrong?
 
Thanks

Problems when run on cordova-android@7

hi,
I'm trying to make the test project work with [email protected] but when I run on Android device, the test app starts but outputs only deviceready.
In the Android Studio Logcat this warn comes back:

Rejecting re-init on previously-failed class java.lang.Class<com.example.HelloCJni>: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/io.cordova.hellocordova-uUJEPTqhZpGH28gw-fLRPg==/base.apk"],nativeLibraryDirectories=[/data/app/io.cordova.hellocordova-uUJEPTqhZpGH28gw-fLRPg==/lib/arm64, /system/lib64, /system/vendor/lib64]]] couldn't find "libhelloc.so"
java.lang.NoClassDefFoundError: com.example.HelloCJni
at com.example.HelloCJni.calculate(Native Method)
at com.example.HelloCPlugin.execute(HelloCPlugin.java:35)
at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:325)
at android.os.Looper.loop(Looper.java:142)
at android.os.HandlerThread.run(HandlerThread.java:65)
Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/io.cordova.hellocordova-uUJEPTqhZpGH28gw-fLRPg==/base.apk"],nativeLibraryDirectories=[/data/app/io.cordova.hellocordova-uUJEPTqhZpGH28gw-fLRPg==/lib/arm64, /system/lib64, /system/vendor/lib64]]] couldn't find "libhelloc.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
at java.lang.System.loadLibrary(System.java:1657)
at com.example.HelloCJni.(HelloCJni.java:12)
at com.example.HelloCJni.getArch(Native Method)
at com.example.HelloCPlugin.execute(HelloCPlugin.java:28)

I do not know if this is the problem but before the support at cordova-android@7, the test app worked with cordova-platform@6.

Thanks

Dlib Library

Hello,

do you think it is possible to get the Dlib library working with your code?

thx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.