我正在使用C++ Builder 10.1 Berlin Enterprise开发一个移动应用程序。该应用程序的目标是扫描条形码,我将Android PDA与条形码扫描仪配合使用。与扫描仪相关的功能包含在JAR文件中。
如何在项目中使用这些功能?
编辑
我已经将Jar添加到我的项目中,但是我不知道要使用扫描功能必须包含什么内容。
编辑2
我用Java2OP创建了一个桥文件。根据Embarcadero文档,我必须将其手动转换为C++,但我不理解Delphi。这是代码:
unit Android.JNI.ATLib;
interface
uses
Androidapi.JNIBridge,
Androidapi.JNI.JavaTypes;
type
// ===== Forward declarations =====
JATLib = interface;//com.atid.lib.ATLib
// ===== Interface declarations =====
JATLibClass = interface(JObjectClass)
['{E264906A-B076-4960-9EAE-17DF2D2AEE74}']
{class} function _GetINTERNAL_PATH: JString;
{class} procedure _SetINTERNAL_PATH(Value: JString);
{class} property INTERNAL_PATH: JString read _GetINTERNAL_PATH write _SetINTERNAL_PATH;
end;
[JavaSignature('com/atid/lib/ATLib')]
JATLib = interface(JObject)
['{EFCFE579-FB94-432F-8DBB-851521F1EED7}']
end;
TJATLib = class(TJavaGenericImport<JATLibClass, JATLib>) end;
implementation
procedure RegisterTypes;
begin
TRegTypes.RegisterType('Android.JNI.ATLib.JATLib', TypeInfo(Android.JNI.ATLib.JATLib));
end;
initialization
RegisterTypes;
end.
您能给我一些建议,将其翻译为C++吗?
我也尝试包含pas文件,但是在编译项目时出现此错误:
Compiler for "Delphi.Personality" and the platform "Android" is missing or unavailable.
编辑3
多亏了post,我才成功将我的网桥文件转换为C++。我试图像这样在应用程序中使用该函数:
TJATScanLib* scan = new TJATScanLib();
_di_JATScanLib scanner = scan->JavaClass->init();
编译期间没有问题,但是在链接步骤中,我遇到了以下错误:
“[ldandroid Erreur] C:\ Users \ Public \ Documents \ Embarcadero \ Studio \ 18.0 \ CatalogRepository \ AndroidNDK-9c_x86_GIB.Build.22858.6822 \ toolchains \ arm-linux-androideabi-4.6 \ prebuilt \ windows \ bin \ arm-linux- androideabi-ld.exe:。\ Android \ Debug \ Connexion.o:在函数TForm_Connexion::TForm_Connexion(System::Classes::TComponent *):C:\ Users \ dylan \ Documents \ Embarcadero \ Studio \ Projets \ PDA_Android / Connexion.cpp:28:错误:
undefined 对'Androidapi::Jnibridge::TJavaGenericImport__2,System::DelphiInterface>::GetJavaClass()的引用”“
和[ldandroid Erreur] C:\ Users \ Public \ Documents \ Embarcadero \ Studio \ 18.0 \ CatalogRepository \ AndroidNDK-9c_x86_GIB.Build.22858.6822 \ toolchains \ arm-linux-androideabi-4.6 \ prebuilt \ windows \ bin \ arm-linux -androideabi-ld.exe:。\ Android \ Debug \ Connexion.o:在函数TForm_Connexion::TForm_Connexion(System::Classes::TComponent *):C:\ Users \ dylan \ Documents \ Embarcadero \ Studio \ Projets \ PDA_Android /Connexion.cpp:30:错误:
undefined 对“vtable for Android::Jni::Atscanlib::TJATScanLib”的引用”
我的桥文件:
#ifndef Android_JNI_ATScanLibH
#define Android_JNI_ATScanLibH
#pragma delphiheader begin
#pragma option push
#pragma option -w- // All warnings off
#pragma option -Vx // Zero-length empty class member
#pragma pack(push,8)
#include <Androidapi.JNIBridge.hpp>
#include <Androidapi.JNI.JavaTypes.hpp>
#include <System.hpp>
#include <SysInit.hpp>
namespace Android{
namespace Jni{
namespace Atscanlib{
__interface JAsyncTask;
typedef System::DelphiInterface<JAsyncTask> _di_JAsyncTask;
__interface JAsyncTaskClass;
typedef System::DelphiInterface<JAsyncTaskClass> _di_JAsyncTaskClass;
__interface JAsyncTask_Status;
typedef System::DelphiInterface<JAsyncTask_Status> _di_JAsyncTask_Status;
__interface JAsyncTask_StatusClass;
typedef System::DelphiInterface<JAsyncTask_StatusClass> _di_JAsyncTask_StatusClass;
__interface JATScanLib;
typedef System::DelphiInterface<JATScanLib> _di_JATScanLib;
__interface JATScanLibClass;
typedef System::DelphiInterface<JATScanLibClass> _di_JATScanLibClass;
__interface JATScanLib_OnResponseListener;
typedef System::DelphiInterface<JATScanLib_OnResponseListener> _di_JATScanLib_OnResponseListener;
__interface JATScanLib_OnResponseListenerClass;
typedef System::DelphiInterface<JATScanLib_OnResponseListenerClass> _di_JATScanLib_OnResponseListenerClass;
__interface JATScanLib_TagSequenceTask;
typedef System::DelphiInterface<JATScanLib_TagSequenceTask> _di_JATScanLib_TagSequenceTask;
__interface JATScanLib_TagSequenceTaskClass;
typedef System::DelphiInterface<JATScanLib_TagSequenceTask> _di_JATScanLib_TagSequenceTaskClass;
__interface JVoid;
typedef System::DelphiInterface<JVoid> _di_JVoid;
__interface JVoidClass;
typedef System::DelphiInterface<JVoid> _di_JVoidClass;
__interface INTERFACE_UUID("{73C141D6-F8D7-4FE4-BFA3-3441B6367189}") JAsyncTaskClass : public Androidapi::Jni::Javatypes::JObjectClass
{
public:
virtual JExecutor _GetSERIAL_EXECUTOR() = 0;
virtual JExecutor _GetTHREAD_POOL_EXECUTOR() = 0;
HIDESBASE virtual _di_JAsyncTask __cdecl init() = 0;
HIDESBASE virtual void __cdecl execute(JRunnable runnable) = 0;
__property JExecutor SERIAL_EXECUTOR = {read = _GetSERIAL_EXECUTOR};
__property JExecutor THREAD_POOL_EXECUTOR = {read = _GetTHREAD_POOL_EXECUTOR};
};
__interface INTERFACE_UUID("{73C141D6-F8D7-4FE4-BFA3-3441B6367189}") JAsyncTask : public Androidapi::Jni::Javatypes::JObject
{
public:
virtual bool __cdecl cancel(bool mayInterruptIfRunning) = 0;
HIDESBASE virtual JObject __cdecl get() = 0;
HIDESBASE virtual JObject __cdecl get(__int64 timeout, JTimeUnit unit_) = 0;
virtual _di_JAsyncTask_Status __cdecl getStatus() = 0;
virtual bool __cdecl isCancelled() = 0;
};
#pragma pack(push,4)
class PASCALIMPLEMENTATION TJAsyncTask : public Androidapi::Jnibridge::TJavaGenericImport__2<_di_JAsyncTaskClass, _di_JAsyncTask>{
typedef Androidapi::Jnibridge::TJavaGenericImport__2<_di_JAsyncTaskClass, _di_JAsyncTask> inherited;
public:
inline __fastcall TJAsyncTask() : Androidapi::Jnibridge::TJavaGenericImport__2<_di_JAsyncTaskClass, _di_JAsyncTask> (){}
inline __fastcall virtual ~TJAsyncTask(void){}
};
#pragma pack(pop)
__interface INTERFACE_UUID("{16452E24-44D5-4E84-990E-3C1916FB372B}") JAsyncTask_StatusClass : public Androidapi::Jni::Javatypes::JEnumClass
{
public:
virtual _di_JAsyncTask_Status _GetFINISHED() = 0;
virtual _di_JAsyncTask_Status _GetPENDING() = 0;
virtual _di_JAsyncTask_Status _GetRUNNING() = 0;
virtual _di_JAsyncTask_Status __cdecl valueOf(JString name) = 0;
virtual TJavaObjectArray__1<_di_JAsyncTask_Status> __cdecl values() = 0;
__property _di_JAsyncTask_Status FINISHED = {read = _GetFINISHED};
__property _di_JAsyncTask_Status PENDING = {read = _GetPENDING};
__property _di_JAsyncTask_Status RUNNING = {read = _GetRUNNING};
};
__interface INTERFACE_UUID("{96B0BCE7-1312-49B9-9F33-43541680B0E7}") JAsyncTask_Status : public Androidapi::Jni::Javatypes::JEnum
{
};
#pragma pack(push,4)
class PASCALIMPLEMENTATION TJAsyncTask_Status : public Androidapi::Jnibridge::TJavaGenericImport__2<_di_JAsyncTask_StatusClass, _di_JAsyncTask_Status>{
typedef Androidapi::Jnibridge::TJavaGenericImport__2<_di_JAsyncTask_StatusClass, _di_JAsyncTask_Status> inherited;
public:
inline __fastcall TJAsyncTask_Status() : Androidapi::Jnibridge::TJavaGenericImport__2<_di_JAsyncTask_StatusClass, _di_JAsyncTask_Status> (){}
inline __fastcall virtual ~TJAsyncTask_Status(void){}
};
#pragma pack(pop)
__interface INTERFACE_UUID("{9A209D1D-07C6-4309-88AD-8A2EF359CF34}") JATScanLibClass : public Androidapi::Jni::Javatypes::JObjectClass
{
public:
virtual int _GetREAD_ENCODING_ERROR() = 0;
virtual int _GetREAD_ERROR() = 0;
virtual int _GetREAD_OK() = 0;
virtual int _GetREAD_TIMEOUT() = 0;
HIDESBASE virtual _di_JATScanLib __cdecl init() = 0;
__property int READ_ENCODING_ERROR = {read = _GetREAD_ENCODING_ERROR};
__property int READ_ERROR = {read = _GetREAD_ERROR};
__property int READ_OK = {read = _GetREAD_OK};
__property int READ_TIMEOUT = {read = _GetREAD_TIMEOUT};
};
__interface INTERFACE_UUID("{74B37E9E-F88A-4EB0-AEDF-538A472223A0}") JATScanLib : public Androidapi::Jni::Javatypes::JObject
{
public:
virtual int __cdecl Read(TJavaArray__1<Byte> P1) = 0;
virtual JString __cdecl getReadResults() = 0;
virtual void __cdecl init() = 0;
virtual void __cdecl setEncoding(JString P1) = 0;
virtual void __cdecl setOnResponseListener(_di_JATScanLib_OnResponseListener P1) = 0;
virtual void __cdecl start() = 0;
virtual void __cdecl stop() = 0;
};
#pragma pack(push,4)
class PASCALIMPLEMENTATION TJATScanLib : public Androidapi::Jnibridge::TJavaGenericImport__2<_di_JATScanLibClass, _di_JATScanLib>{
typedef Androidapi::Jnibridge::TJavaGenericImport__2<_di_JATScanLibClass, _di_JATScanLib> inherited;
public:
inline __fastcall TJATScanLib() : Androidapi::Jnibridge::TJavaGenericImport__2<_di_JATScanLibClass, _di_JATScanLib> (){}
inline __fastcall virtual ~TJATScanLib(void){}
};
#pragma pack(pop)
__interface INTERFACE_UUID("{654B87BA-B4EE-4102-85E9-9FDFF3C82BAA}") JATScanLib_OnResponseListenerClass : public Androidapi::Jnibridge::IJavaClass
{
};
__interface INTERFACE_UUID("{35AC182B-7684-47EA-9BA8-07B504F85943}") JATScanLib_OnResponseListener : public Androidapi::Jnibridge::IJavaInstance
{
public:
virtual void __cdecl onResponse(int P1) = 0;
};
#pragma pack(push,4)
class PASCALIMPLEMENTATION TJATScanLib_OnResponseListener : public Androidapi::Jnibridge::TJavaGenericImport__2<_di_JATScanLib_OnResponseListenerClass, _di_JATScanLib_OnResponseListener>{
typedef Androidapi::Jnibridge::TJavaGenericImport__2<_di_JATScanLib_OnResponseListenerClass, _di_JATScanLib_OnResponseListener> inherited;
public:
inline __fastcall TJATScanLib_OnResponseListener() : Androidapi::Jnibridge::TJavaGenericImport__2<_di_JATScanLib_OnResponseListenerClass, _di_JATScanLib_OnResponseListener> (){}
inline __fastcall virtual ~TJATScanLib_OnResponseListener(void){}
};
#pragma pack(pop)
__interface INTERFACE_UUID("{1CF84DF6-6115-4FB5-9967-B55E74A3155C}") JATScanLib_TagSequenceTaskClass : public _di_JAsyncTaskClass
{
};
__interface INTERFACE_UUID("{B83D8A9F-C1C4-4023-B1D8-3D9ABFB1FD2C}") JATScanLib_TagSequenceTask : public _di_JAsyncTask
{
};
#pragma pack(push,4)
class PASCALIMPLEMENTATION TJATScanLib_TagSequenceTask : public Androidapi::Jnibridge::TJavaGenericImport__2<_di_JATScanLib_TagSequenceTaskClass, _di_JATScanLib_TagSequenceTask>{
typedef Androidapi::Jnibridge::TJavaGenericImport__2<_di_JATScanLib_TagSequenceTaskClass, _di_JATScanLib_TagSequenceTask> inherited;
public:
inline __fastcall TJATScanLib_TagSequenceTask() : Androidapi::Jnibridge::TJavaGenericImport__2<_di_JATScanLib_TagSequenceTaskClass, _di_JATScanLib_TagSequenceTask> (){}
inline __fastcall virtual ~TJATScanLib_TagSequenceTask(void){}
};
#pragma pack(pop)
__interface INTERFACE_UUID("{E5AB6B2B-2580-469B-BBF6-C226984DFEBE}") JVoidClass : public Androidapi::Jni::Javatypes::JObjectClass
{
public:
virtual Jlang_Class _GetTYPE() = 0;
__property Jlang_Class TYPE = {read = _GetTYPE};
};
__interface INTERFACE_UUID("{013CC63A-938C-46BE-ACAC-BA854F2F6AC8}") JVoid : public Androidapi::Jni::Javatypes::JObject
{
};
#pragma pack(push,4)
class PASCALIMPLEMENTATION TJVoid : public Androidapi::Jnibridge::TJavaGenericImport__2<_di_JVoidClass, _di_JVoid>{
typedef Androidapi::Jnibridge::TJavaGenericImport__2<_di_JVoidClass, _di_JVoid> inherited;
public:
inline __fastcall TJVoid() : Androidapi::Jnibridge::TJavaGenericImport__2<_di_JVoidClass, _di_JVoid> (){}
inline __fastcall virtual ~TJVoid(void){}
};
#pragma pack(pop)
}
}
}
#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_ANDROID_JNI_ATLIB)
using namespace Android::Jni::Atscanlib;
#endif
#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_ANDROID_JNI)
using namespace Android::Jni;
#endif
#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_ANDROID)
using namespace Android;
#endif
#pragma pack(pop)
#pragma option pop
#pragma delphiheader end.
#endif
最佳答案
Embarcadero的文档涵盖了该主题:
Using a Custom Set of Java Libraries In Your RAD Studio Android Apps
您在项目中缺少的是步骤2。您可以使用Embarcadero的Java2OP工具生成该桥接文件。