delphi xe 自带的Android Demo程序 编译时正常,但当Run 时报如下错误,请大神帮忙看一下
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了delphi xe 自带的Android Demo程序 编译时正常,但当Run 时报如下错误,请大神帮忙看一下相关的知识,希望对你有一定的参考价值。
[PAClient Error] Error: E2312 Unable to execute '"C:\Users\Public\Documents\Embarcadero\Studio\17.0\PlatformSDKs\android-sdk-windows\build-tools\24.0.0\aapt.exe" package -f -M "C:\Users\hfb.huang\Desktop\Accelerometer\Android\Debug\Accelerometer\AndroidManifest.xml" -F "C:\Users\hfb.huang\Desktop\Accelerometer\Android\Debug\Accelerometer\bin\Accelerometer-unsigned.apk" -I "C:\Users\Public\Documents\Embarcadero\Studio\17.0\PlatformSDKs\android-sdk-windows\platforms\android-24\android.jar" -S "C:\Users\hfb.huang\Desktop\Accelerometer\Android\Debug\Accelerometer\res" -A "C:\Users\hfb.huang\Desktop\Accelerometer\Android\Debug\Accelerometer\assets" "C:\Users\hfb.huang\Desktop\Accelerometer\Android\Debug\Accelerometer\library" "C:\Users\hfb.huang\Desktop\Accelerometer\Android\Debug\Accelerometer\classes"' (Error -1073741819)
参考技术A 没有安装sdk或sdk路径不符追问SDK已经安装好了,路径也重新设过啊,还是不行。
追答要在option中sdk管理中设置路径,设置正确后三角形标志会消失
如何检查Android和iOS上的网络是否可用(Delphi XE5)
- 如何检查Android和iOS上的网络是否可用?
试试这个:
unit Network;
interface
function IsConnected: Boolean;
function IsWiFiConnected: Boolean;
function IsMobileConnected: Boolean;
implementation
uses
System.SysUtils,
Androidapi.JNIBridge,
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.JavaTypes,
FMX.Helpers.Android, Androidapi.Helpers, Misc;
type
JConnectivityManager = interface;
JNetworkInfo = interface;
JNetworkInfoClass = interface(JObjectClass)
['{E92E86E8-0BDE-4D5F-B44E-3148BD63A14C}']
end;
[JavaSignature('android/net/NetworkInfo')]
JNetworkInfo = interface(JObject)
['{6DF61A40-8D17-4E51-8EF2-32CDC81AC372}']
{Methods}
function isAvailable: Boolean; cdecl;
function isConnected: Boolean; cdecl;
function isConnectedOrConnecting: Boolean; cdecl;
end;
TJNetworkInfo = class(TJavaGenericImport<JNetworkInfoClass, JNetworkInfo>) end;
JConnectivityManagerClass = interface(JObjectClass)
['{E03A261F-59A4-4236-8CDF-0068FC6C5FA1}']
{Property methods}
function _GetTYPE_WIFI: Integer; cdecl;
function _GetTYPE_WIMAX: Integer; cdecl;
function _GetTYPE_MOBILE: Integer; cdecl;
{Properties}
property TYPE_WIFI: Integer read _GetTYPE_WIFI;
property TYPE_WIMAX: Integer read _GetTYPE_WIMAX;
property TYPE_MOBILE: Integer read _GetTYPE_MOBILE;
end;
[JavaSignature('android/net/ConnectivityManager')]
JConnectivityManager = interface(JObject)
['{1C4C1873-65AE-4722-8EEF-36BBF423C9C5}']
{Methods}
function getActiveNetworkInfo: JNetworkInfo; cdecl;
function getNetworkInfo(networkType: Integer): JNetworkInfo; cdecl;
end;
TJConnectivityManager = class(TJavaGenericImport<JConnectivityManagerClass, JConnectivityManager>) end;
function GetConnectivityManager: JConnectivityManager;
var
ConnectivityServiceNative: JObject;
begin
ConnectivityServiceNative := SharedActivityContext.getSystemService(TJContext.JavaClass.CONNECTIVITY_SERVICE);
if not Assigned(ConnectivityServiceNative) then
raise Exception.Create('Could not locate Connectivity Service');
Result := TJConnectivityManager.Wrap(
(ConnectivityServiceNative as ILocalObject).GetObjectID);
if not Assigned(Result) then
raise Exception.Create('Could not access Connectivity Manager');
end;
function IsConnected: Boolean;
var
ConnectivityManager: JConnectivityManager;
ActiveNetwork: JNetworkInfo;
begin
ConnectivityManager := GetConnectivityManager;
ActiveNetwork := ConnectivityManager.getActiveNetworkInfo;
Result := Assigned(ActiveNetwork) and ActiveNetwork.isConnected;
end;
function IsWiFiConnected: Boolean;
var
ConnectivityManager: JConnectivityManager;
WiFiNetwork: JNetworkInfo;
begin
ConnectivityManager := GetConnectivityManager;
WiFiNetwork := ConnectivityManager.getNetworkInfo(TJConnectivityManager.JavaClass.TYPE_WIFI);
Result := WiFiNetwork.isConnected;
end;
function IsMobileConnected: Boolean;
var
ConnectivityManager: JConnectivityManager;
MobileNetwork: JNetworkInfo;
begin
ConnectivityManager := GetConnectivityManager;
MobileNetwork := ConnectivityManager.getNetworkInfo(TJConnectivityManager.JavaClass.TYPE_MOBILE);
Result := MobileNetwork.isConnected;
end;
end.
非常感谢blong的解决方案。因为它开始在德尔福柏林工作,我重新编写了模块代码。我希望这很有用。
在RAD 10.1上可以完全使用Androidapi.JNI.Net.pas模块。但是对于该研究可能有助于在单独的模块中提出所提出的功能。
unit Androidapi.JNI.Network;
interface
function IsConnected: Boolean;
function IsWiFiConnected: Boolean;
function IsMobileConnected: Boolean;
implementation
uses
System.SysUtils,
Androidapi.JNIBridge,
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.JavaTypes,
Androidapi.JNI.Net,
FMX.Helpers.Android,
Androidapi.Helpers;
// type
// JConnectivityManager = interface;
// JNetworkInfo = interface;
//
// JNetworkInfoClass = interface(JObjectClass)
// ['{E92E86E8-0BDE-4D5F-B44E-3148BD63A14C}']
// end;
//
// [JavaSignature('android/net/NetworkInfo')]
// JNetworkInfo = interface(JObject)
// ['{6DF61A40-8D17-4E51-8EF2-32CDC81AC372}']
// { Methods }
// function isAvailable: Boolean; cdecl;
// function IsConnected: Boolean; cdecl;
// function isConnectedOrConnecting: Boolean; cdecl;
// end;
// TJNetworkInfo = class(TJavaGenericImport<JNetworkInfoClass, JNetworkInfo>)
// end;
//
// JConnectivityManagerClass = interface(JObjectClass)
// ['{E03A261F-59A4-4236-8CDF-0068FC6C5FA1}']
// { Property methods }
// function _GetTYPE_WIFI: Integer; cdecl;
// function _GetTYPE_WIMAX: Integer; cdecl;
// function _GetTYPE_MOBILE: Integer; cdecl;
// { Properties }
// property TYPE_WIFI: Integer read _GetTYPE_WIFI;
// property TYPE_WIMAX: Integer read _GetTYPE_WIMAX;
// property TYPE_MOBILE: Integer read _GetTYPE_MOBILE;
// end;
//
// [JavaSignature('android/net/ConnectivityManager')]
// JConnectivityManager = interface(JObject)
// ['{1C4C1873-65AE-4722-8EEF-36BBF423C9C5}']
// { Methods }
// function getActiveNetworkInfo: JNetworkInfo; cdecl;
// function getNetworkInfo(networkType: Integer): JNetworkInfo; cdecl;
// end;
// TJConnectivityManager = class(TJavaGenericImport<JConnectivityManagerClass, JConnectivityManager>)
// end;
function GetConnectivityManager: JConnectivityManager;
var
ConnectivityServiceNative: JObject;
begin
ConnectivityServiceNative := TAndroidHelper.Context.getSystemService
(TJContext.JavaClass.CONNECTIVITY_SERVICE);
if not Assigned(ConnectivityServiceNative) then
raise Exception.Create('Could not locate Connectivity Service');
Result := TJConnectivityManager.Wrap((ConnectivityServiceNative as ILocalObject).GetObjectID);
if not Assigned(Result) then
raise Exception.Create('Could not access Connectivity Manager');
end;
function IsConnected: Boolean;
var
ConnectivityManager: JConnectivityManager;
ActiveNetwork: JNetworkInfo;
begin
ConnectivityManager := GetConnectivityManager;
ActiveNetwork := ConnectivityManager.getActiveNetworkInfo;
Result := Assigned(ActiveNetwork) and ActiveNetwork.IsConnected;
end;
function IsWiFiConnected: Boolean;
var
ConnectivityManager: JConnectivityManager;
WiFiNetwork: JNetworkInfo;
begin
ConnectivityManager := GetConnectivityManager;
WiFiNetwork := ConnectivityManager.getNetworkInfo(TJConnectivityManager.JavaClass.TYPE_WIFI);
Result := WiFiNetwork.IsConnected;
end;
function IsMobileConnected: Boolean;
var
ConnectivityManager: JConnectivityManager;
MobileNetwork: JNetworkInfo;
begin
ConnectivityManager := GetConnectivityManager;
MobileNetwork := ConnectivityManager.getNetworkInfo(TJConnectivityManager.JavaClass.TYPE_MOBILE);
Result := MobileNetwork.IsConnected;
end;
end.
我现在没有在我面前的源目录,但这应该有助于指出正确的方向。
我相信你将能够在delphi中重做下面的android解决方案:Detect whether there is an Internet connection available on Android
编辑:此行完全复制该函数的第一行,只是不确定返回什么类型。一旦你有了这个功能的其余部分应该是微不足道的:
SharedActivitiyContext.getSystemService(TJContext.JavaClass.ConnectivityService)
uses System.Net.HttpClient
function CheckInternet: boolean;
begin
Result := false;
with THTTPClient.Create do
try
try
Result := Head('http://google.com').StatusCode < 400;
except
end;
finally
Free;
end;
end;
在fmxexpress网站上的解决方案。您通常使用IdTCPClient组件并检查您是否可以连接到google.com
以上是关于delphi xe 自带的Android Demo程序 编译时正常,但当Run 时报如下错误,请大神帮忙看一下的主要内容,如果未能解决你的问题,请参考以下文章