简体   繁体   中英

android NDK build issue

when I tried the NDK build command here is the error i got

        D:\AndroidWorkSpace\cppTestProj>D:\android-ndk-r8b-windows\android-ndk-r8b\ndk-b
uild.cmd
Android NDK: WARNING: Unsupported source file extensions in jni/Android.mk for m
odule cppTestProj
Android NDK:   LOCAL_SRC_FILES :=
"Compile++ thumb : cppTestProj <= maintestapp.cpp
jni/maintestapp.cpp:1:19: fatal error: iostream: No such file or directory
compilation terminated.
make: *** [obj/local/armeabi/objs/cppTestProj/maintestapp.o] Error 1

The JNI folder has the following files:

maintestapp.cpp
Test_array_type.cpp
Test_array_type.h

Could u pls let me know the issue. Im not using Cygwin for the same. Am I missing any files?

Here is the make file

    LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := cppTestProj
LOCAL_SRC_FILES := LOCAL_SRC_FILES := maintestapp.cpp \
                   Test_array_type.cpp

include $(BUILD_SHARED_LIBRARY)

here is the cpp file

#include<iostream>
#include"Test_array_type.h"
#include<stdio.h>
#include<conio.h>
using namespace std;
int main()
{
    Test_array_type test_array;
    Test_array_type *ptest_array1;

    test_array.AddToList(10);
    test_array.AddToList(20);
    test_array.AddToList("Basha");
    test_array.PrintList();
    ptest_array1 = test_array.clonelist();
    test_array.DeleteFromList(3);
    test_array.AddToList(10);
    test_array.AddToList(20);
    test_array.AddToList(30);
    test_array.AddToList(40);
    test_array.AddToList(true);
    test_array.AddToList("Java Beon APP");
    test_array.PrintList();
    ptest_array1->PrintList();
    getch();
    return true;
}

you should not run the 'ndk-build' command from your projects jni folder. To execute the Android.mk file run ndk-bild command within your root directory of project.

Your Android.mk should be look like this

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := cppTestProj
LOCAL_SRC_FILES := maintestapp.cpp \
                   Test_array_type.cpp

include $(BUILD_SHARED_LIBRARY)

Then run your ndk-build command

You can see this link for sample Android.mk file

Update:

static {
        System.loadLibrary("hello-jni");
    }

for more information please refer HelloJni.java file of sample project.

Thanks

您需要添加LOCAL_C_INCLUDES并包含可视C ++包含文件夹,因为您正在使用它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM