Android ndk Android构建系统。本地图书馆。编译时出现很多代码错误
我有一个本机库,在我的android应用程序中可以通过ndk正常工作。现在我需要用这个库编译android。但我在尝试这样做时犯了一些神秘的错误Android ndk Android构建系统。本地图书馆。编译时出现很多代码错误,android-ndk,java-native-interface,android-build,Android Ndk,Java Native Interface,Android Build,我有一个本机库,在我的android应用程序中可以通过ndk正常工作。现在我需要用这个库编译android。但我在尝试这样做时犯了一些神秘的错误 target thumb C++: md5b <= external/libmd5b/jni/md5b.cpp target thumb C++: md5b <= external/libmd5b/jni/md5.cpp external/libmd5b/jni/md5b.cpp:2:18: error: string: No such f
target thumb C++: md5b <= external/libmd5b/jni/md5b.cpp
target thumb C++: md5b <= external/libmd5b/jni/md5.cpp
external/libmd5b/jni/md5b.cpp:2:18: error: string: No such file or directory
external/libmd5b/jni/md5b.cpp:3:20: error: iostream: No such file or directory
external/libmd5b/jni/md5b.cpp:4:19: error: fstream: No such file or directory
In file included from external/libmd5b/jni/md5.cpp:2:
external/libmd5b/jni/md5.h:5:20: error: iostream: No such file or directory
external/libmd5b/jni/md5.cpp:6:18: error: string: No such file or directory
In file included from external/libmd5b/jni/md5b.cpp:6:
external/libmd5b/jni/md5.h:23: error: expected unqualified-id before '&' token
external/libmd5b/jni/md5.h:23: error: expected ')' before '&' token
external/libmd5b/jni/md5.h:23: error: expected ';' before '&' token
external/libmd5b/jni/md5.h:27: error: 'string' in namespace 'std' does not name a type
external/libmd5b/jni/md5.h:28: error: ISO C++ forbids declaration of 'ostream' with no type
external/libmd5b/jni/md5.h:28: error: 'ostream' is neither function nor member function; cannot be declared friend
external/libmd5b/jni/md5.h:28: error: expected ';' before '&' token
external/libmd5b/jni/md5.h:58: error: 'string' in namespace 'std' does not name a type
external/libmd5b/jni/md5b.cpp: In function '_jstring* Md5B(JNIEnv*, _jobject*, _jstring*)':
external/libmd5b/jni/md5b.cpp:18: error: 'string' is not a member of 'std'
external/libmd5b/jni/md5b.cpp:18: error: expected ';' before 'strpath'
external/libmd5b/jni/md5b.cpp:19: error: 'ifstream' was not declared in this scope
external/libmd5b/jni/md5b.cpp:19: error: expected ';' before 'inFile'
external/libmd5b/jni/md5b.cpp:20: error: 'inFile' was not declared in this scope
external/libmd5b/jni/md5b.cpp:20: error: 'strpath' was not declared in this scope
external/libmd5b/jni/md5b.cpp:21: error: 'string' is not a member of 'std'
external/libmd5b/jni/md5b.cpp:21: error: expected ';' before 'line'
external/libmd5b/jni/md5b.cpp:22: error: 'string' is not a member of 'std'
external/libmd5b/jni/md5b.cpp:22: error: expected ';' before 'strFile'
external/libmd5b/jni/md5b.cpp:25: error: 'line' was not declared in this scope
external/libmd5b/jni/md5b.cpp:25: error: 'getline' was not declared in this scope
external/libmd5b/jni/md5b.cpp:26: error: 'strFile' was not declared in this scope
external/libmd5b/jni/md5b.cpp:29: error: 'string' is not a member of 'std'
external/libmd5b/jni/md5b.cpp:29: error: expected ';' before 'md5R'
external/libmd5b/jni/md5b.cpp:30: error: 'md5R' was not declared in this scope
make: *** [out/target/product/generic/obj/SHARED_LIBRARIES/md5b_intermediates/md5b.o] Error 1
make: *** Waiting for unfinished jobs....
In file included from external/libmd5b/jni/md5.cpp:2:
external/libmd5b/jni/md5.h:23: error: expected unqualified-id before '&' token
external/libmd5b/jni/md5.h:23: error: expected ')' before '&' token
external/libmd5b/jni/md5.h:23: error: expected ';' before '&' token
external/libmd5b/jni/md5.h:27: error: 'string' in namespace 'std' does not name a type
external/libmd5b/jni/md5.h:28: error: ISO C++ forbids declaration of 'ostream' with no type
external/libmd5b/jni/md5.h:28: error: 'ostream' is neither function nor member function; cannot be declared friend
external/libmd5b/jni/md5.h:28: error: expected ';' before '&' token
external/libmd5b/jni/md5.h:58: error: 'string' in namespace 'std' does not name a type
external/libmd5b/jni/md5.cpp:79: error: expected unqualified-id before '&' token
external/libmd5b/jni/md5.cpp:79: error: expected ')' before '&' token
external/libmd5b/jni/md5.cpp:79: error: expected initializer before '&' token
external/libmd5b/jni/md5.cpp:303: error: 'string' in namespace 'std' does not name a type
external/libmd5b/jni/md5.cpp:318: error: expected constructor, destructor, or type conversion before '&' token
external/libmd5b/jni/md5.cpp:325: error: 'string' in namespace 'std' does not name a type
make: *** [out/target/product/generic/obj/SHARED_LIBRARIES/md5b_intermediates/md5.o] Error 1
Application.mk
APP_STL:=stlport_static
APP_MODULES := md5b
部分./build/target/product/full.mk
PRODUCT_PACKAGES := \
Camera \
libmd5b
md5b.cpp
#include <jni.h>
#include <string>
#include <iostream>
#include <fstream>
#include <android/log.h>
#include "md5.h"
using namespace std;
extern "C" {
JNIEXPORT jstring JNICALL Md5B //This function named without aplication_activity_etc because it should be visible system wide. Is it right syntax?
(JNIEnv * env, jobject obj, jstring fpath);
};
JNIEXPORT jstring JNICALL Md5B
(JNIEnv * env, jobject obj, jstring fpath)
{
std::string strpath = env->GetStringUTFChars(fpath, NULL);
ifstream inFile;
inFile.open(strpath.c_str());
std::string line;
std::string strFile;
while (!inFile.eof())
{
getline(inFile, line);
strFile += line;
}
inFile.close();
std::string md5R = md5(strFile);
char* chmd5R = new char [md5R.length()];
strcpy (chmd5R, md5R.c_str());
return env->NewStringUTF(chmd5R);
}
#包括
#包括
#包括
#包括
#包括和
我错过了什么以及如何修复它?当您在Android构建树(而不是NDK)中构建本机代码时,您没有自动STL支持。您必须手动添加STL头和库,例如
LOCAL_STATIC_LIBRARIES += libstlport_static
LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
帮助我轻松开始使用std字符串
我创建了Application.mk
,只添加了一行:
APP_STL := stlport_static
然后我在我的CPP文件中添加了#include
,并使用std::string s(“Lorem”)创建了字符串
因为使用命名空间
被认为是一种不好的做法
我在我的Android.mk行中添加了如下内容:LOCAL_STATIC_LIBRARIES+=libstlport_STATIC libstdc++libm libc,但仍然有相同的错误。您还需要LOCAL_C_INCLUDES中的STL头,抱歉,我没有明确提及。是的。图书馆已经通过你的方式编译了。没有错误和警告。但当我在/system/lib中找不到它时,我感到困惑。然而,这应该是另一个问题。非常感谢你。
APP_STL := stlport_static