├── compile-ios ├── .gitignore ├── compile-android ├── compile-android.cmd ├── src ├── ios │ ├── libs │ │ ├── libmylib.a │ │ └── headers │ │ │ ├── mylib.h │ │ │ ├── mypart.h │ │ │ └── mycomponent.h │ ├── c_getArch.h │ ├── HelloCPlugin.h │ ├── Makefile │ ├── c_getArch.c │ ├── HelloCPlugin.m │ └── ios_compile.sh ├── android │ ├── libs │ │ ├── x86 │ │ │ └── libhelloc.so │ │ ├── x86_64 │ │ │ └── libhelloc.so │ │ ├── arm64-v8a │ │ │ └── libhelloc.so │ │ └── armeabi-v7a │ │ │ └── libhelloc.so │ ├── obj │ │ └── local │ │ │ ├── x86 │ │ │ └── libhelloc.so │ │ │ ├── x86_64 │ │ │ └── libhelloc.so │ │ │ ├── arm64-v8a │ │ │ └── libhelloc.so │ │ │ └── armeabi-v7a │ │ │ └── libhelloc.so │ ├── HelloCJni.java │ ├── build-extras.gradle │ ├── jni │ │ ├── HelloCJni.h │ │ ├── Android.mk │ │ └── HelloCJni.c │ └── HelloCPlugin.java └── common │ ├── mylib │ ├── mycomponent.c │ ├── parts │ │ ├── mypart.c │ │ └── mypart.h │ ├── mylib.c │ ├── mylib.h │ └── mycomponent.h │ ├── hello.h │ └── hello.c ├── .github ├── FUNDING.yml ├── PULL_REQUEST_TEMPLATE.md └── ISSUE_TEMPLATE │ ├── documentation-issue.md │ ├── feature_request.md │ └── bug_report.md ├── package.json ├── www └── helloc.js ├── plugin.xml ├── README.md └── LICENSE /compile-ios: -------------------------------------------------------------------------------- 1 | cd src/ios 2 | ./ios_compile.sh 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | src/android/obj/local/*/objs/helloc/ 3 | -------------------------------------------------------------------------------- /compile-android: -------------------------------------------------------------------------------- 1 | cd src/android 2 | rm -Rf libs/ obj/ 3 | ndk-build 4 | cd ../.. -------------------------------------------------------------------------------- /compile-android.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | cd src\android 3 | rmdir libs obj /S /Q 4 | ndk-build.cmd 5 | cd ..\.. -------------------------------------------------------------------------------- /src/ios/libs/libmylib.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpa99c/cordova-plugin-hello-c/HEAD/src/ios/libs/libmylib.a -------------------------------------------------------------------------------- /src/android/libs/x86/libhelloc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpa99c/cordova-plugin-hello-c/HEAD/src/android/libs/x86/libhelloc.so -------------------------------------------------------------------------------- /src/android/libs/x86_64/libhelloc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpa99c/cordova-plugin-hello-c/HEAD/src/android/libs/x86_64/libhelloc.so -------------------------------------------------------------------------------- /src/android/libs/arm64-v8a/libhelloc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpa99c/cordova-plugin-hello-c/HEAD/src/android/libs/arm64-v8a/libhelloc.so -------------------------------------------------------------------------------- /src/android/obj/local/x86/libhelloc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpa99c/cordova-plugin-hello-c/HEAD/src/android/obj/local/x86/libhelloc.so -------------------------------------------------------------------------------- /src/android/libs/armeabi-v7a/libhelloc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpa99c/cordova-plugin-hello-c/HEAD/src/android/libs/armeabi-v7a/libhelloc.so -------------------------------------------------------------------------------- /src/android/obj/local/x86_64/libhelloc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpa99c/cordova-plugin-hello-c/HEAD/src/android/obj/local/x86_64/libhelloc.so -------------------------------------------------------------------------------- /src/android/obj/local/arm64-v8a/libhelloc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpa99c/cordova-plugin-hello-c/HEAD/src/android/obj/local/arm64-v8a/libhelloc.so -------------------------------------------------------------------------------- /src/android/obj/local/armeabi-v7a/libhelloc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dpa99c/cordova-plugin-hello-c/HEAD/src/android/obj/local/armeabi-v7a/libhelloc.so -------------------------------------------------------------------------------- /src/common/mylib/mycomponent.c: -------------------------------------------------------------------------------- 1 | // 2 | // mycomponent.c 3 | // Cross-platform C library component 4 | // 5 | 6 | #include "mycomponent.h" 7 | #include 8 | 9 | int sum(int y, int z) { 10 | return y+z; 11 | } 12 | -------------------------------------------------------------------------------- /src/common/mylib/parts/mypart.c: -------------------------------------------------------------------------------- 1 | // 2 | // mypart.c 3 | // Cross-platform C library component 4 | // 5 | 6 | #include "mypart.h" 7 | #include 8 | 9 | int multiply(int y, int z) { 10 | return y*z; 11 | } 12 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [ dpa99c ] 4 | custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=ZRD3W47HQ3EMJ&source=url 5 | patreon: dpa99c 6 | ko_fi: davealden -------------------------------------------------------------------------------- /src/common/hello.h: -------------------------------------------------------------------------------- 1 | // 2 | // hello.h 3 | // Cross-platform C functionality 4 | // 5 | 6 | #ifndef hello_h 7 | #define hello_h 8 | 9 | #include 10 | 11 | char* c_hello(char* input); 12 | int crash(); 13 | 14 | #endif /* hello_h */ 15 | -------------------------------------------------------------------------------- /src/common/mylib/mylib.c: -------------------------------------------------------------------------------- 1 | // 2 | // mylib.c 3 | // Cross-platform C library 4 | // 5 | 6 | #include "mylib.h" 7 | #include "mycomponent.h" 8 | #include "mypart.h" 9 | #include 10 | 11 | 12 | int calculate(int y, int z) { 13 | return multiply(sum(y,z),z); 14 | } 15 | -------------------------------------------------------------------------------- /src/ios/c_getArch.h: -------------------------------------------------------------------------------- 1 | // 2 | // c_getArch 3 | // Platform-specific implementation to retrieve CPU architecture. 4 | // iOS implementation 5 | // 6 | 7 | #ifndef c_getArch 8 | #define c_getArch 9 | 10 | #include 11 | 12 | char* getCPUArch(); 13 | #endif /* c_getArch */ 14 | -------------------------------------------------------------------------------- /src/common/mylib/mylib.h: -------------------------------------------------------------------------------- 1 | // 2 | // mylib.h 3 | // Cross-platform C library 4 | // 5 | 6 | #ifndef mylib 7 | #define mylib 8 | 9 | #include 10 | 11 | // a function prototype for a function exported by library: 12 | extern int calculate(int y, int z); 13 | 14 | #endif /* mylib */ 15 | -------------------------------------------------------------------------------- /src/ios/libs/headers/mylib.h: -------------------------------------------------------------------------------- 1 | // 2 | // mylib.h 3 | // Cross-platform C library 4 | // 5 | 6 | #ifndef mylib 7 | #define mylib 8 | 9 | #include 10 | 11 | // a function prototype for a function exported by library: 12 | extern int calculate(int y, int z); 13 | 14 | #endif /* mylib */ 15 | -------------------------------------------------------------------------------- /src/ios/libs/headers/mypart.h: -------------------------------------------------------------------------------- 1 | // 2 | // mypart.h 3 | // Cross-platform C library component 4 | // 5 | 6 | #ifndef mypart 7 | #define mypart 8 | 9 | #include 10 | 11 | // a function prototype for a function internal to the library: 12 | int multiply(int y, int z); 13 | 14 | #endif /* mypart */ 15 | -------------------------------------------------------------------------------- /src/common/mylib/parts/mypart.h: -------------------------------------------------------------------------------- 1 | // 2 | // mypart.h 3 | // Cross-platform C library component 4 | // 5 | 6 | #ifndef mypart 7 | #define mypart 8 | 9 | #include 10 | 11 | // a function prototype for a function internal to the library: 12 | int multiply(int y, int z); 13 | 14 | #endif /* mypart */ 15 | -------------------------------------------------------------------------------- /src/common/mylib/mycomponent.h: -------------------------------------------------------------------------------- 1 | // 2 | // mycomponent.h 3 | // Cross-platform C library component 4 | // 5 | 6 | #ifndef mycomponent 7 | #define mycomponent 8 | 9 | #include 10 | 11 | // a function prototype for a function internal to the library: 12 | int sum(int y, int z); 13 | 14 | #endif /* mycomponent */ 15 | -------------------------------------------------------------------------------- /src/ios/HelloCPlugin.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface HelloCPlugin : CDVPlugin 4 | 5 | - (void) hello:(CDVInvokedUrlCommand*)command; 6 | - (void) getArch:(CDVInvokedUrlCommand*)command; 7 | - (void) calculate:(CDVInvokedUrlCommand*)command; 8 | - (void) causeCrash:(CDVInvokedUrlCommand*)command; 9 | 10 | @end 11 | -------------------------------------------------------------------------------- /src/ios/libs/headers/mycomponent.h: -------------------------------------------------------------------------------- 1 | // 2 | // mycomponent.h 3 | // Cross-platform C library component 4 | // 5 | 6 | #ifndef mycomponent 7 | #define mycomponent 8 | 9 | #include 10 | 11 | // a function prototype for a function internal to the library: 12 | int sum(int y, int z); 13 | 14 | #endif /* mycomponent */ 15 | -------------------------------------------------------------------------------- /src/ios/Makefile: -------------------------------------------------------------------------------- 1 | 2 | SRC=$(wildcard $(SRC_PATH)/*.c) 3 | OBJS=$(patsubst %.c,%.o,$(SRC)) 4 | 5 | LDLIBS=$(patsubst %, $(TARGET_PATH)/lib%.a, $(DEPS)) 6 | 7 | all:$(ARCH)-$(LIBNAME).a 8 | 9 | $(ARCH)-$(LIBNAME).a: $(OBJS) 10 | @echo $(LDLIBS) $(OBJS) 11 | $(AR) rcs $@ $(OBJS) 12 | ranlib $@ 13 | 14 | clean: 15 | rm $(OBJS) 16 | 17 | .PHONY: realclean 18 | realclean: clean 19 | rm *.a 20 | -------------------------------------------------------------------------------- /src/android/HelloCJni.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | public class HelloCJni { 4 | 5 | // C-function interface 6 | public static native String hello(String input); 7 | public static native String getArch(); 8 | public static native int calculate(int x, int y); 9 | public static native int crash(); 10 | 11 | // load library 12 | static { 13 | System.loadLibrary("helloc"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/common/hello.c: -------------------------------------------------------------------------------- 1 | // 2 | // hello.c 3 | // Cross-platform C functionality 4 | // 5 | 6 | #include "hello.h" 7 | #include 8 | #include 9 | 10 | char* concat(const char* s1, const char* s2){ 11 | char* result = malloc(strlen(s1)+strlen(s2)+1);//+1 for the zero-terminator 12 | strcpy(result, s1); 13 | strcat(result, s2); 14 | return result; 15 | } 16 | 17 | char* c_hello(char* input) { 18 | char* hello= "I'm a cross-platform pure C function. You sent me this: "; 19 | char* result = concat(hello, input); 20 | return result; 21 | } 22 | 23 | 24 | int crash() { 25 | exit(1); 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.1.1", 3 | "name": "cordova-plugin-hello-c", 4 | "cordova_name": "Hello C", 5 | "description": "", 6 | "author": "Dave Alden", 7 | "license": "MIT", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/dpa99c/cordova-plugin-hello-c.git" 11 | }, 12 | "issue": "https://github.com/dpa99c/cordova-plugin-hello-c/issues", 13 | "cordova": { 14 | "id": "cordova-plugin-hello-c", 15 | "platforms": [ 16 | "android", 17 | "ios" 18 | ] 19 | }, 20 | "keywords": [ 21 | "ecosystem:cordova", 22 | "cordova", 23 | "android", 24 | "ios" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /www/helloc.js: -------------------------------------------------------------------------------- 1 | /*global cordova, module*/ 2 | 3 | module.exports = { 4 | getArch: function (successCallback, errorCallback) { 5 | cordova.exec(successCallback, errorCallback, "HelloCPlugin", "getArch", []); 6 | }, 7 | hello: function (input, successCallback, errorCallback) { 8 | cordova.exec(successCallback, errorCallback, "HelloCPlugin", "hello", [input]); 9 | }, 10 | calculate: function (x, y, successCallback, errorCallback) { 11 | cordova.exec(successCallback, errorCallback, "HelloCPlugin", "calculate", [x, y]); 12 | }, 13 | causeCrash: function (successCallback, errorCallback) { 14 | cordova.exec(successCallback, errorCallback, "HelloCPlugin", "causeCrash", []); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /src/android/build-extras.gradle: -------------------------------------------------------------------------------- 1 | android { 2 | packagingOptions { 3 | pickFirst 'app/src/main/jniLibs/arm64-v8a/libhelloc.so' 4 | pickFirst 'app/src/main/jniLibs/armeabi-v7a/libhelloc.so' 5 | pickFirst 'app/src/main/jniLibs/x86/libhelloc.so' 6 | pickFirst 'app/src/main/jniLibs/x86_64/libhelloc.so' 7 | } 8 | defaultConfig { 9 | ndk { 10 | abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' 11 | } 12 | externalNativeBuild { 13 | ndkBuild { 14 | arguments "-j4" 15 | } 16 | } 17 | } 18 | 19 | externalNativeBuild { 20 | ndkBuild { 21 | path "app/src/main/java/c/android/jni/Android.mk" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/ios/c_getArch.c: -------------------------------------------------------------------------------- 1 | // 2 | // c_getArch 3 | // Platform-specific implementation to retrieve CPU architecture. 4 | // iOS implementation 5 | // 6 | 7 | #include "c_getArch.h" 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | char* getCPUArch() 14 | { 15 | char* cpu; 16 | size_t size; 17 | cpu_type_t type; 18 | cpu_subtype_t subtype; 19 | size = sizeof(type); 20 | sysctlbyname("hw.cputype", &type, &size, NULL, 0); 21 | 22 | size = sizeof(subtype); 23 | sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0); 24 | 25 | // values for cputype and cpusubtype defined in mach/machine.h 26 | if (type == CPU_TYPE_X86_64) { 27 | cpu = "x86_64"; 28 | } else if (type == CPU_TYPE_X86) { 29 | cpu = "x86"; 30 | } else if (type == CPU_TYPE_ARM) { 31 | cpu = "ARM"; 32 | } else if (type == CPU_TYPE_ARM64) { 33 | cpu = "ARM_64"; 34 | }else{ 35 | cpu = "UNKNOWN"; 36 | } 37 | return cpu; 38 | } 39 | -------------------------------------------------------------------------------- /src/android/jni/HelloCJni.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include 3 | /* Header for class com_example_HelloCJni */ 4 | 5 | #ifndef _Included_com_example_HelloCJni 6 | #define _Included_com_example_HelloCJni 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | /* 12 | * Class: com_example_HelloCJni 13 | * Method: getArch 14 | * Signature: ()Ljava/lang/String; 15 | */ 16 | JNIEXPORT jstring JNICALL Java_com_example_HelloCJni_getArch (JNIEnv *, jclass); 17 | /* 18 | * Class: com_example_HelloCJni 19 | * Method: hello 20 | * Signature: (Ljava/lang/String;)Ljava/lang/String; 21 | */ 22 | JNIEXPORT jstring JNICALL Java_com_example_HelloCJni_hello (JNIEnv *, jclass, jstring); 23 | 24 | 25 | 26 | /* 27 | * Class: com_example_HelloCJni 28 | * Method: calculate 29 | * Signature: (Ljava/lang/String;)Ljava/lang/String; 30 | */ 31 | JNIEXPORT jstring JNICALL Java_com_example_HelloCJni_calculate (JNIEnv *, jclass, jint, jint); 32 | 33 | 34 | /* 35 | * Class: com_example_HelloCJni 36 | * Method: crash 37 | * Signature: (Ljava/lang/String;)Ljava/lang/String; 38 | */ 39 | JNIEXPORT jstring JNICALL Java_com_example_HelloCJni_crash( JNIEnv* env, jclass thiz); 40 | 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | #endif 46 | -------------------------------------------------------------------------------- /src/android/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Android Makefile 2 | 3 | APP_PLATFORM := android-21 4 | APP_ABI := armeabi-v7a arm64-v8a x86 x86_64 5 | 6 | PATH_SEP := / 7 | 8 | LOCAL_PATH := $(call my-dir) 9 | include $(CLEAR_VARS) 10 | 11 | #traverse all the directory and subdirectory 12 | define walk 13 | $(wildcard $(1)) $(foreach e, $(wildcard $(1)$(PATH_SEP)*), $(call walk, $(e))) 14 | endef 15 | 16 | SRC_LIST := 17 | INCLUDE_LIST := 18 | 19 | 20 | ################################ 21 | # prepare shared lib 22 | 23 | LOCAL_MODULE := helloc 24 | 25 | # JNI interface files 26 | INCLUDE_LIST += $(LOCAL_PATH) 27 | SRC_LIST += $(wildcard $(LOCAL_PATH)/*.c) 28 | 29 | # Cross-platform common files 30 | INCLUDE_LIST += $(LOCAL_PATH)/../../common/ 31 | ifeq ($(OS),Windows_NT) 32 | INCLUDE_LIST += ${shell dir $(LOCAL_PATH)\..\..\common\ /ad /b /s} 33 | else 34 | INCLUDE_LIST += ${shell find $(LOCAL_PATH)/../../common/ -type d} 35 | endif 36 | SRC_LIST += $(filter %.c, $(call walk, $(LOCAL_PATH)/../../common)) 37 | 38 | 39 | $(info LOCAL_PATH:$(LOCAL_PATH)) 40 | $(info SRC_LIST:$(SRC_LIST)) 41 | $(info INCLUDE_LIST:$(INCLUDE_LIST)) 42 | 43 | LOCAL_C_INCLUDES := $(INCLUDE_LIST) 44 | LOCAL_SRC_FILES := $(SRC_LIST:$(LOCAL_PATH)/%=%) 45 | 46 | LOCAL_CFLAGS += -std=c99 47 | LOCAL_CPPFLAGS := -fblocks 48 | TARGET_PLATFORM := android-27 49 | LOCAL_DISABLE_FATAL_LINKER_WARNINGS := true 50 | LOCAL_LDLIBS += -Wl,--no-warn-shared-textrel 51 | LOCAL_LDFLAGS += -fuse-ld=gold 52 | 53 | include $(BUILD_SHARED_LIBRARY) 54 | 55 | ################################ 56 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## PR Type 2 | What kind of change does this PR introduce? 3 | 4 | 5 | - [ ] Bugfix 6 | - [ ] Feature 7 | - [ ] Code style update (formatting, local variables) 8 | - [ ] Refactoring (no functional changes, no api changes) 9 | - [ ] Documentation changes 10 | - [ ] Other... Please describe: 11 | 12 | 13 | 14 | ## PR Checklist 15 | For bug fixes / features, please check if your PR fulfills the following requirements: 16 | 17 | - [ ] Testing has been carried out for the changes have been added 18 | - [ ] Regression testing has been carried out for existing functionality 19 | - [ ] Docs have been added / updated 20 | 21 | ## What is the purpose of this PR? 22 | 23 | 24 | 25 | ## Does this PR introduce a breaking change? 26 | - [ ] Yes 27 | - [ ] No 28 | 29 | 30 | 31 | ## What testing has been done on the changes in the PR? 32 | 33 | 34 | ## What testing has been done on existing functionality? 35 | 36 | 37 | ## Other information -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation-issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Documentation issue 3 | about: Describe an issue with the documentation 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 16 | 17 | 18 | # Documentation issue 19 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 15 | 16 | 17 | # Feature request 18 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/android/jni/HelloCJni.c: -------------------------------------------------------------------------------- 1 | // 2 | // HelloCJni 3 | // 4 | #include 5 | #include 6 | #include 7 | 8 | // Platform-specific C implementation to get current CPU architecture 9 | JNIEXPORT jstring JNICALL Java_com_example_HelloCJni_getArch( JNIEnv* env, jclass thiz ) 10 | { 11 | #if defined(__arm__) 12 | #if defined(__ARM_ARCH_7A__) 13 | #if defined(__ARM_NEON__) 14 | #if defined(__ARM_PCS_VFP) 15 | #define ABI "armeabi-v7a/NEON (hard-float)" 16 | #else 17 | #define ABI "armeabi-v7a/NEON" 18 | #endif 19 | #else 20 | #if defined(__ARM_PCS_VFP) 21 | #define ABI "armeabi-v7a (hard-float)" 22 | #else 23 | #define ABI "armeabi-v7a" 24 | #endif 25 | #endif 26 | #else 27 | #define ABI "armeabi" 28 | #endif 29 | #elif defined(__i386__) 30 | #define ABI "x86" 31 | #elif defined(__x86_64__) 32 | #define ABI "x86_64" 33 | #elif defined(__mips64) /* mips64el-* toolchain defines __mips__ too */ 34 | #define ABI "mips64" 35 | #elif defined(__mips__) 36 | #define ABI "mips" 37 | #elif defined(__aarch64__) 38 | #define ABI "arm64-v8a" 39 | #else 40 | #define ABI "unknown" 41 | #endif 42 | return (*env)->NewStringUTF(env, ABI); 43 | } 44 | 45 | // Android JNI wrapper for cross-platform C implementation 46 | JNIEXPORT jstring JNICALL Java_com_example_HelloCJni_hello( JNIEnv* env, jclass thiz, jstring j_input) 47 | { 48 | // Call the cross-platform shared C function 49 | char* c_input = strdup((*env)->GetStringUTFChars(env, j_input, 0)); 50 | char* output = c_hello(c_input); 51 | return (*env)->NewStringUTF(env, output); 52 | } 53 | 54 | // Android JNI wrapper for cross-platform C library 55 | JNIEXPORT jstring JNICALL Java_com_example_HelloCJni_calculate( JNIEnv* env, jclass thiz, jint j_x, jint j_y) 56 | { 57 | // Call the cross-platform shared C function 58 | int x = (int) j_x; 59 | int y = (int) j_y; 60 | int result = calculate(x, y); 61 | return result; 62 | } 63 | 64 | // Android JNI wrapper for cross-platform C library 65 | JNIEXPORT jstring JNICALL Java_com_example_HelloCJni_crash( JNIEnv* env, jclass thiz) 66 | { 67 | // Call the cross-platform shared C function 68 | int result = crash(); 69 | return result; 70 | } 71 | -------------------------------------------------------------------------------- /src/ios/HelloCPlugin.m: -------------------------------------------------------------------------------- 1 | #import "HelloCPlugin.h" 2 | #include "c_getArch.h" 3 | #include "hello.h" 4 | #include "mylib.h" 5 | @implementation HelloCPlugin 6 | 7 | - (void)getArch:(CDVInvokedUrlCommand*)command 8 | { 9 | NSString* msg = [NSString stringWithFormat: @"iOS %s", getCPUArch()]; 10 | 11 | CDVPluginResult* result = [CDVPluginResult 12 | resultWithStatus:CDVCommandStatus_OK 13 | messageAsString:msg]; 14 | 15 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 16 | } 17 | 18 | - (void)hello:(CDVInvokedUrlCommand*)command 19 | { 20 | //c_hello(); 21 | NSString* input = [[command arguments] objectAtIndex:0]; 22 | char* c_input = strdup([input UTF8String]); 23 | NSString* output = [NSString stringWithFormat: @"iOS says: %s", c_hello(c_input)]; 24 | 25 | CDVPluginResult* result = [CDVPluginResult 26 | resultWithStatus:CDVCommandStatus_OK 27 | messageAsString:output]; 28 | 29 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 30 | } 31 | 32 | - (void)calculate:(CDVInvokedUrlCommand *)command 33 | { 34 | NSString* a = [[command arguments] objectAtIndex:0]; 35 | NSString* b = [[command arguments] objectAtIndex:1]; 36 | 37 | int x = a.intValue; 38 | int y = b.intValue; 39 | int output = calculate(x,y); 40 | 41 | NSLog(@"%@", [NSString stringWithFormat: @"x=%d, y=%d, result=%d",x,y,output]); 42 | 43 | CDVPluginResult* result = [CDVPluginResult 44 | resultWithStatus:CDVCommandStatus_OK 45 | messageAsInt:output]; 46 | 47 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 48 | } 49 | 50 | - (void)causeCrash:(CDVInvokedUrlCommand *)command 51 | { 52 | int output = crash(); // Call the C function 53 | 54 | // should not reach here 55 | NSLog(@"%@", [NSString stringWithFormat: @"result=%d",output]); 56 | CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsInt:output]; 57 | [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /src/ios/ios_compile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PLATFORMPATH="/Applications/Xcode.app/Contents/Developer/Platforms" 4 | TOOLSPATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin" 5 | export LIBNAME="mylib" 6 | export SRC_ROOT="../common/mylib" 7 | IPHONEOS_DEPLOYMENT_TARGET="8.0" 8 | pwd=`pwd` 9 | TEMP_DIR="$pwd/temp" 10 | OUTPUT_DIR="$pwd/libs" 11 | HEADERS_DIR="$OUTPUT_DIR/headers" 12 | 13 | LIPO_INPUTS="" 14 | 15 | findLatestSDKVersion() 16 | { 17 | sdks=`ls $PLATFORMPATH/$1.platform/Developer/SDKs` 18 | arr=() 19 | for sdk in $sdks 20 | do 21 | arr[${#arr[@]}]=$sdk 22 | done 23 | 24 | # Last item will be the current SDK, since it is alpha ordered 25 | count=${#arr[@]} 26 | if [ $count -gt 0 ]; then 27 | sdk=${arr[$count-1]:${#1}} 28 | num=`expr ${#sdk}-4` 29 | SDKVERSION=${sdk:0:$num} 30 | else 31 | SDKVERSION="8.0" 32 | fi 33 | } 34 | 35 | 36 | buildit() 37 | { 38 | target=$1 39 | hosttarget=$1 40 | platform=$2 41 | 42 | if [[ $hosttarget == "x86_64" ]]; then 43 | hostarget="i386" 44 | elif [[ $hosttarget == "arm64" ]]; then 45 | hosttarget="arm" 46 | fi 47 | 48 | export ARCH="$hosttarget" 49 | 50 | export CC="$(xcrun -sdk iphoneos -find clang)" 51 | #CPP="$CC -E" 52 | export CFLAGS="-arch ${target} -isysroot $PLATFORMPATH/$platform.platform/Developer/SDKs/$platform$SDKVERSION.sdk -miphoneos-version-min=$SDKVERSION -fembed-bitcode" 53 | export AR=$(xcrun -sdk iphoneos -find ar) 54 | export RANLIB=$(xcrun -sdk iphoneos -find ranlib) 55 | export LDFLAGS="-mthumb -arch ${target} -isysroot $PLATFORMPATH/$platform.platform/Developer/SDKs/$platform$SDKVERSION.sdk -fembed-bitcode" 56 | 57 | export SRC_PATH="$TEMP_DIR" 58 | export TARGET_PATH="temp/$target" 59 | export TARGET_DIR="$pwd/$TARGET_PATH" 60 | 61 | make 62 | make clean 63 | 64 | mkdir -p $TARGET_DIR 65 | 66 | LIB_FILENAME="$ARCH-$LIBNAME.a" 67 | 68 | mv $LIB_FILENAME $TARGET_DIR 69 | LIPO_INPUTS="$LIPO_INPUTS $TARGET_DIR/$LIB_FILENAME" 70 | 71 | } 72 | mkdir -p $TEMP_DIR $HEADERS_DIR 73 | cp `find $SRC_ROOT -type f \( -name "*.c" -or -name "*.h" \)` $TEMP_DIR 74 | 75 | findLatestSDKVersion iPhoneOS 76 | 77 | # buildit armv7 iPhoneOS 78 | # buildit armv7s iPhoneOS 79 | buildit arm64 iPhoneOS 80 | # buildit i386 iPhoneSimulator 81 | buildit x86_64 iPhoneSimulator 82 | 83 | LIPO=$(xcrun -sdk iphoneos -find lipo) 84 | $LIPO -create $LIPO_INPUTS -output $OUTPUT_DIR/lib$LIBNAME.a 85 | 86 | mv $TEMP_DIR/*.h $HEADERS_DIR 87 | 88 | rm -Rf $TEMP_DIR -------------------------------------------------------------------------------- /src/android/HelloCPlugin.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.apache.cordova.*; 4 | import org.json.JSONArray; 5 | import org.json.JSONException; 6 | import android.app.Activity; 7 | import android.os.Bundle; 8 | import android.util.Log; 9 | 10 | public class HelloCPlugin extends CordovaPlugin { 11 | 12 | protected static final String TAG = "HelloCPlugin"; 13 | protected CallbackContext context; 14 | 15 | @Override 16 | public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { 17 | context = callbackContext; 18 | boolean result = true; 19 | try { 20 | if (action.equals("hello")) { 21 | 22 | String input = data.getString(0); 23 | String jniOutput = HelloCJni.hello(input); 24 | String output = "Android says: " + jniOutput; 25 | callbackContext.success(output); 26 | 27 | } else if (action.equals("getArch")) { 28 | String jniOutput = HelloCJni.getArch(); 29 | String output = "Android " + jniOutput; 30 | callbackContext.success(output); 31 | 32 | } else if (action.equals("calculate")) { 33 | int x = data.getInt(0); 34 | int y = data.getInt(1); 35 | int jniOutput = HelloCJni.calculate(x,y); 36 | callbackContext.success(jniOutput); 37 | } else if (action.equals("causeCrash")) { 38 | cordova.getThreadPool().execute(new Runnable() { 39 | public void run() { 40 | int jniOutput = HelloCJni.crash(); 41 | callbackContext.success(jniOutput); // should not reach here 42 | } 43 | }); 44 | } 45 | else { 46 | handleError("Invalid action"); 47 | result = false; 48 | } 49 | } catch (Exception e) { 50 | handleException(e); 51 | result = false; 52 | } 53 | return result; 54 | } 55 | 56 | 57 | /** 58 | * Handles an error while executing a plugin API method. 59 | * Calls the registered Javascript plugin error handler callback. 60 | * 61 | * @param errorMsg Error message to pass to the JS error handler 62 | */ 63 | private void handleError(String errorMsg) { 64 | try { 65 | Log.e(TAG, errorMsg); 66 | context.error(errorMsg); 67 | } catch (Exception e) { 68 | Log.e(TAG, e.toString()); 69 | } 70 | } 71 | 72 | private void handleException(Exception exception) { 73 | handleError(exception.toString()); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Report a problem 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 15 | 16 | 17 | 18 | # Bug report 19 | 20 | 21 | **CHECKLIST** 22 | - [ ] I have read the [issue reporting guidelines](README#reporting-issues) 23 | 24 | - [ ] I confirm this is a suspected bug or issue that will affect other users 25 | 26 | 27 | - [ ] I have reproduced the issue using the example projector provided the necessary information to reproduce the issue. 28 | 29 | 30 | - [ ] I have read the documentation thoroughly and it does not help solve my issue. 31 | 32 | 33 | - [ ] I have checked that no similar issues (open or closed) already exist. 34 | 35 | 36 | **Current behavior:** 37 | 38 | 39 | 40 | 44 | 45 | **Expected behavior:** 46 | 47 | 48 | **Steps to reproduce:** 49 | 50 | 51 | **Screenshots** 52 | 53 | 54 | **Environment information** 55 | 56 | - Cordova CLI version 57 | - `cordova -v` 58 | - Cordova platform version 59 | - `cordova platform ls` 60 | - Plugins & versions installed in project (including this plugin) 61 | - `cordova plugin ls` 62 | - Dev machine OS and version, e.g. 63 | - OSX 64 | - `sw_vers` 65 | - Windows 10 66 | - `winver` 67 | 68 | _Runtime issue_ 69 | - Device details 70 | - _e.g. iPhone X, Samsung Galaxy S8, iPhone X Simulator, Pixel XL Emulator_ 71 | - OS details 72 | - _e.g. iOS 12.2, Android 9.0_ 73 | 74 | _Android build issue:_ 75 | - Node JS version 76 | - `node -v` 77 | - Gradle version 78 | - `ls platforms/android/.gradle` 79 | - Target Android SDK version 80 | - `android:targetSdkVersion` in `AndroidManifest.xml` 81 | - Android SDK details 82 | - `sdkmanager --list | sed -e '/Available Packages/q'` 83 | 84 | _iOS build issue:_ 85 | - Node JS version 86 | - `node -v` 87 | - XCode version 88 | 89 | 90 | **Related code:** 91 | ``` 92 | insert any relevant code here such as plugin API calls / input parameters 93 | ``` 94 | 95 | **Console output** 96 |
97 | console output 98 | 99 | ``` 100 | 101 | // Paste any relevant JS/native console output here 102 | 103 | ``` 104 | 105 |


106 | 107 | **Other information:** 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | Hello 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cordova-plugin-hello-c 2 | ====================== 3 | 4 | A simple example of a Cordova plugin that uses pure C code. 5 | 6 | It illustrates how to use platform-specific (either Android or iOS) C code and how to share C code cross-platform (between Android and iOS). 7 | 8 | For Android it utilizes the Android NDK to compile architecture-specific libraries and a JNI wrapper to expose the C functions to the Java plugin API. 9 | 10 | For iOS it uses the pure C source code in place alongside the Objective-C plugin wrapper, as well as an example cross-platform library compiled as a static library for iOS. 11 | 12 | # usage example 13 | 14 | - Clone the [test project](https://github.com/dpa99c/cordova-plugin-hello-c-test) 15 | - Add Android and iOS platforms: `cordova platform add android && cordova platform add ios` 16 | - Run: `cordova run android` / `cordova run ios` 17 | 18 | # Plugin structure 19 | 20 | - `plugin.xml` - Specifies the plugin's source files and libraries to copy to the platforms of the Cordova project into which the plugin is installed 21 | - `compile-android` and `compile-android.cmd` - Script to recompile C source code as a shared library for use with Android platform 22 | - `compile-ios` - Script to recompile cross-platform C library as static library for use with iOS platform 23 | - `src/` - C source code and build scripts 24 | - `common/` - cross-platform C source code to run on both Android and iOS 25 | - `mylib/` - example cross-platform C library 26 | - `android/` - source code and build scripts for Android platform 27 | - `build-extras.gradle` - Gradle build script to link up the NDK make file for debugging C code in Android Studio 28 | - `HelloCPlugin.java` - Provides the native Java implementation for Android of the Cordova plugin 29 | - `HelloCJni.java` - Provides the Java interface to the underlying JNI C implementation 30 | - `jni/` - JNI C implementation and build script 31 | - `HelloJni.c` - C implementation of the JNI interface defined by `HelloCJni.java`, including 32 | - Android-specific implementation to get current CPU architecture 33 | - interfaces to cross-platform C functionality 34 | - `Android.mk` - NDK Make script to build the C source code into architecture-specific shared libraries 35 | - `libs/` - contains folders for the various architecture-specific shared libraries built by the NDK Make script 36 | - `ios/` - source code and build scripts for iOS platform 37 | - `c_getArch.c` & `c_getArch.h` - iOS-specific implementation to get current CPU architecture 38 | - `HelloCPlugin.c` & `HelloCPlugin.h` - Provides the native Objective-C implementation for iOS of the Cordova plugin 39 | - `ios_compile.sh` - Script to compile the cross-platform example library in `src/common/mylib/` as a static library 40 | - `Makefile` - Make script invoked by the above script to perform the C compilation. 41 | - `libs/` - the compiled cross-platform library 42 | - `libmylib.a` - the compiled cross-platform library as a multi-architecture static library 43 | - `headers/` - the header files of the cross-platform library (static libraries require the headers externally) 44 | 45 | 46 | # Recompiling libraries 47 | If you modify the C source files, be sure to re-build the compiled libraries. 48 | 49 | ## Android 50 | 51 | You can re-build the `libhelloc.so` binaries using the ndk-build script. 52 | 53 | To do so: 54 | 55 | - Install Android NDK as [instructed here](https://developer.android.com/ndk/guides/index.html) 56 | - Add the NDK install path to your path environment variable 57 | - By default it's installed under $ANDROID_SDK_HOME/ndk-bundle 58 | - e.g. `export PATH=$PATH;$ANDROID_SDK_HOME/ndk-bundle` 59 | - Set the ANDROID_NDK_HOME environment variable to your NDK install path 60 | - e.g. `export ANDROID_NDK_HOME=$ANDROID_SDK_HOME/ndk-bundle` 61 | - Open terminal in plugin root folder 62 | - Run `./compile-android` (`compile-android.cmd` on Windows) 63 | 64 | If you are editing the C source code of the plugin in place in the example project: 65 | 66 | - Modify the C source in `plugins/cordova-plugin-hello-c/src/android/jni` or `plugins/cordova-plugin-hello-c/src/common` 67 | - Open terminal in `plugins/cordova-plugin-hello-c` 68 | - Delete `src/android/libs` and `src/android/obj` 69 | - Run `compile-android` (`compile-android.cmd` on Windows) 70 | - From the project root, remove and re-add the android platform to apply the plugin changes to the project 71 | `cordova platform rm android && cordova platform add android` 72 | 73 | ## iOS 74 | If you modify the C source code in `common/mylib/` you'll need to rebuild the static library and headers in `src/ios/libs`. 75 | 76 | - Open terminal in plugin root folder 77 | - Run `./compile-ios` 78 | 79 | If you are editing the C source code of the plugin in place in the example project: 80 | 81 | - Modify the C source in `plugins/cordova-plugin-hello-c/src/ios/` or `plugins/cordova-plugin-hello-c/src/common` 82 | - Open terminal in `plugins/cordova-plugin-hello-c` 83 | - Run `./compile-ios` 84 | - From the project root, remove and re-add the platform to apply the plugin changes to the project 85 | `cordova platform rm ios && cordova platform add ios` 86 | 87 | # Debugging C source code 88 | 89 | ## Android 90 | 91 | - The Android NDK enables C/C++ source code to be debugged in Android Studio alongside Java. 92 | - To do so, the source code must be included but **not** the compiled libraries. 93 | - To debug this plugin in Android Studio do the following: 94 | - Edit `plugin.xml` and in the `` block, comment out the source-file lines in the PRODUCTION block which include the compiled libraries 95 | - Remove/re-add the plugin or Android platform in your project to update the plugin files in the platform project 96 | - Open the Android platform project (`platforms/android`) in Android Studio 97 | - Connect an Android device for debugging 98 | - Use the Project Explorer to find and open one of the `.c` source files 99 | - Place a breakpoint, for example on a `return` statement 100 | - Select "Run" > "Debug ..." from the menu 101 | 102 | ## iOS 103 | 104 | - Since iOS is a C-based platform, C debugging is inherently supported in the Xcode IDE 105 | - However, to debug the C code in the static library `src/ios/libs/libmylib.a`, you'll need to comment out the library files and comment in the source code for it: 106 | - Edit `plugin.xml` and in the `` block 107 | - comment out the lines in the PRODUCTION block which include the compiled library and headers. 108 | - comment in the the commented-out lines in the DEBUG block which will include the uncompiled C source code for the library 109 | - Remove/re-add the plugin or iOS platform in your project to update the plugin files in the platform project 110 | - Use the OSX Finder to browse to `platforms/ios/` in your Cordova project and double-click the `.xcodeproj` file to open it in Xcode. 111 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------