我正在尝试在我的android项目中捆绑本机库,以便我的应用程序在尝试访问库时不会崩溃。我正在尝试捆绑的库名为opencv_java246.so
由于这是一个最初为非android系统设计和开发的现有项目,后来扩展到android工作,eclipse中的项目不是android项目。
现在,我得到的例外是:
E/AndroidRuntime(32760): FATAL EXCEPTION: main
E/AndroidRuntime(32760): java.lang.ExceptionInInitializerError
E/AndroidRuntime(32760): at com.acunia.fleet.docuscan.android.DocuScanActivity.onActivityResult(DocuScanActivity.java:83)
E/AndroidRuntime(32760): at android.app.Activity.dispatchActivityResult(Activity.java:4649)
E/AndroidRuntime(32760): at android.app.ActivityThread.deliverResults(ActivityThread.java:2976)
E/AndroidRuntime(32760): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3023)
E/AndroidRuntime(32760): at android.app.ActivityThread.access$1100(ActivityThread.java:123)
E/AndroidRuntime(32760): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177)
E/AndroidRuntime(32760): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(32760): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(32760): at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime(32760): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(32760): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(32760): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime(32760): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
E/AndroidRuntime(32760): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(32760): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opencv_java: findLibrary returned null
E/AndroidRuntime(32760): at java.lang.Runtime.loadLibrary(Runtime.java:365)
E/AndroidRuntime(32760): at java.lang.System.loadLibrary(System.java:539)
E/AndroidRuntime(32760): at org.opencv.highgui.Highgui.<clinit>(Highgui.java:313)
E/AndroidRuntime(32760): ... 14 more
我查找了如何在我的android上手动安装库,但无法找到任何有用的东西,因为我的android没有root,我无法将文件复制到我的机器人文件系统。
shell@android:/ $ mkdir libs
mkdir failed for libs, Read-only file system
我尝试在现有项目中创建名为/lib/armeabi
,/libs/armeabi
和/libs/libs/armeabi
的文件夹,但其中没有一个包含我的apk的本机库。
我尝试使用Android.mk
文件并将我的.so库放在/lib/armeabi
中但是当我构建apk时,它仍然无法找到库(我不知道它是否可以甚至包括apk中的库。
这是ant构建目标:
<target name="apk" depends="unpack">
<mkdir dir="${build.dir}/class" />
<mkdir dir="${build.dir}/java" />
<filter token="fleet-android-sar.version" value="${fleet-android-sar.version}" />
<filter token="fleet-android-sar.versioncode" value="${fleet-android-sar.versioncode}" />
<copy todir="${build.dir}" filtering="true">
<fileset dir="${resource.dir}" includes="AndroidManifest.xml" />
</copy>
<copy todir="${build.dir}/class" filtering="false">
<fileset dir="${library.class.dir}/">
<include name="com/acunia/fleet/android/**" />
<include name="com/acunia/fleet/docuscan/android/*" />
<include name="com/acunia/fleet/geofence/common/*" />
<include name="com/acunia/fleet/geofence/android/**" />
<include name="com/acunia/fleet/logbook/*" />
<include name="com/acunia/fleet/logbook/android/*" />
<include name="com/acunia/fleet/logbook/motion/*" />
<exclude name="com/acunia/fleet/logbook/motion/MotionAnalyzer*" />
<include name="com/acunia/fleet/messenger/android/**" />
<include name="com/acunia/fleet/messenger/common/**" />
<include name="com/acunia/fleet/messenger/agent/MessageListener*" />
<include name="com/acunia/fleet/messenger/agent/TextMessage*" />
<include name="com/acunia/fleet/planningassistant/android/**" />
<include name="com/acunia/fleet/planningassistant/common/**" />
<include name="com/acunia/fleet/reporting/*" />
<include name="com/acunia/fleet/desktop/impl/android/**" />
<include name="com/acunia/fleet/desktop/pairing/**" />
<exclude name="com/acunia/fleet/reporting/AWTReportView*" />
<include name="com/acunia/fleet/reporting/android/*" />
<include name="com/acunia/fleet/reporting/common/*" />
<include name="com/acunia/fleet/reporting/impl/*" />
<include name="com/acunia/fleet/reporting/impl/ReportActivator*" />
<include name="com/acunia/fleet/session/*" />
<include name="com/acunia/fleet/session/android/*" />
<include name="com/acunia/fleet/session/impl/*" />
<exclude name="com/acunia/fleet/session/Identification*" />
<exclude name="com/acunia/fleet/session/Identificator*" />
<include name="com/acunia/fleet/scanner/android/*" />
<include name="com/acunia/fleet/scanner/common/*" />
<include name="com/acunia/fleet/filetransfer/*" />
<include name="com/acunia/fleet/filetransfer/android/**" />
<include name="org/osgi/framework/*" />
<include name="org/osgi/service/cm/*" />
<include name="org/osgi/service/log/*" />
<include name="com/acunia/otf/agent/android/*" />
<include name="com/acunia/otf/net/android/node/msg/**" />
<include name="com/acunia/otf/net/node/msg/mux/**" />
<include name="com/acunia/otf/net/share/msg/**" />
<include name="com/acunia/util/net/node/logtransfer/**" />
<include name="com/acunia/util/net/android/logtransfer/**" />
<include name="com/acunia/service/auth/**" />
<include name="com/acunia/service/tracking/android/**" />
<include name="com/acunia/service/tracking/common/**" />
<include name="com/acunia/fleet/state/android/**" />
<include name="com/acunia/fleet/state/common/**" />
<include name="com/acunia/fleet/state/controller/listener/**" />
<include name="com/acunia/service/logging/android/**" />
<include name="com/acunia/service/logging/http/client/**" />
<include name="com/acunia/android/util/**" />
<include name="com/acunia/android/widget/**" />
<include name="com/acunia/osgi/local/Log.class" />
<include name="com/acunia/time/**" />
<include name="com/google/zxing/**" />
<include name="com/acunia/zxing/**" />
<include name="javax/microedition/io/**" />
<include name="com/acunia/util/remoteterm/client/**" />
<include name="com/acunia/util/remoteterm/android/**" />
<include name="com/acunia/service/lbs/Address.class" />
<include name="com/acunia/service/lbs/Coordinate.class" />
<include name="com/acunia/service/position/android/**" />
<include name="com/acunia/service/position/nmea/NMEAParser*" />
<include name="com/acunia/service/position/nmea/NMEAPositionHandler*"/>
<include name="org/opencv/**"/>
</fileset>
</copy>
<exec executable="${aapt}" failonerror="true" taskname="aapt">
<arg value="package" />
<arg value="-f" />
<arg value="-M" />
<arg value="${build.dir}/AndroidManifest.xml" />
<arg value="-F" />
<arg value="${build.dir}/android-resources.jar" />
<arg value="-I" />
<arg value="${library.release.dir}/${android.jar}" />
<arg value="-S" />
<arg value="${resource.dir}/res" />
<arg value="-m" />
<arg value="-J" />
<arg value="${build.dir}/java" />
</exec>
<javac srcdir="${build.dir}/java" debug="false" deprecation="false" includeAntRuntime="no" includeJavaRuntime="no" destdir="${build.dir}/class">
<bootclasspath>
<pathelement location="${java.home}/lib/rt.jar" />
<fileset dir="${java.home}/lib/ext/" includes="**/*.jar" />
</bootclasspath>
</javac>
<exec executable="${dx}" failonerror="true" taskname="dx">
<arg value="--dex" />
<arg value="--no-locals" />
<arg value="--verbose" />
<arg value="--output=${build.dir}/classes.dex" />
<arg value="${build.dir}/class" />
</exec>
<copy file="${build.dir}/android-resources.jar" toFile="${build.dir}/fleetxps-orig.apk"/>
<zip destfile="${build.dir}/fleetxps-orig.apk" keepcompression="true" update="true" basedir="${build.dir}" includes="classes.dex"/>
<exec executable="jarsigner" failonerror="true" taskname="jarsigner">
<arg value="-keystore" />
<arg value="testkeystore" />
<arg value="-storepass" />
<arg value="acunia" />
<arg value="-keypass" />
<arg value="acunia" />
<arg value="-signedjar" />
<arg value="${build.dir}/fleetxps-signed.apk" />
<arg value="${build.dir}/fleetxps-orig.apk" />
<arg value="acunia" />
</exec>
<exec executable="${zipalign}" failonerror="true" taskname="zipalign">
<arg value="-f" />
<arg value="4" />
<arg value="${build.dir}/fleetxps-signed.apk" />
<arg value="${release.lib.dir}/fleetxps.apk" />
</exec>
</target>
<target name="sar" depends="apk">
<filter token="fleet-android.version" value="${xps-android-sar.version}" />
<filter token="component.version" value="${component.version}" />
<filter token="component.build.tag" value="${component.build.tag}" />
<copy todir="${build.dir}" filtering="true">
<fileset dir="${resource.dir}/" includes="xps-android.xml" />
</copy>
<sar destfile="${release.lib.dir}/fleet-android-${xps-android-sar.version}.sar" provisioning="${build.dir}/xps-android.xml">
<clientbundle name="sar.tgt">
<fileset dir="${release.lib.dir}" type="application/x-apk">
<include name="xps.apk" />
</fileset>
<fileset dir="${library.resource.dir}/config" type="application/x-osgi-config">
<include name="com.otf.agent.adapter.diff.config" />
<include name="com.otf.net.node.ioprovider.otfdatagram.config" />
<include name="com.messenger.agent.config.config" />
<include name="com.messenger.agent.list.config" />
<include name="com.reporting.config" />
<include name="com.filetransfer.config" />
<include name="com.scanner.config" />
<include name="com.reporting.store.config" />
<include name="com.service.auth.agent.module.basic.config" />
<include name="com.state.controller.StateController.config" />
<include name="com.service.tracking.osgi.impl.RealTimeTrackingAgent.config" />
<include name="com.service.tracking.osgi.impl.TrackingAgent.config" />
<include name="com.service.logging.buffers.config" />
<include name="com.service.logging.http.client.config" />
</fileset>
</clientbundle>
</sar>
</target>
<target name="deploy" depends="apk, redeploy" />
<target name="redeploy">
<exec executable="${adb}" failonerror="true" taskname="adb">
<!-- <arg value="-d" /> -->
<arg value="install" />
<arg value="-r" />
<arg value="${release.lib.dir}/xps.apk" />
</exec>
</target>
有没有办法使用这个ant构建文件将我的本机库与我的apk捆绑在一起?或任何其他有效的方式也会很棒。
谢谢!