将 Scala 2.8 移植到 Netbeans NBAndroid 项目中...我缺少哪些步骤?

发布于 2024-08-28 10:44:07 字数 5914 浏览 9 评论 0原文

由于 Apple 最近的 T+C 狂欢,我对 Android 开发产生了兴趣。

无论如何,我正在尝试在 Netbeans 6.8 中运行一个混合语言 Android 2.1 项目(使用 NBAndroid 0.10 插件)。两种语言是 Java 和 Scala(2.8 head build)。为了让您对应用程序现在的功能有一个基本的了解,它只是一个简单的“Hello World”应用程序。

为了构建它,我修改了项目的 build.xml 文件:

 <target name="-pre-compile" depends="init">
   <property name="scala-home" value="/Users/development/Applications/scala-2.8.0/build/pack"/>
   <property name="scala-library" value="/Users/development/Applications/scala-2.8.0/build/pack/lib/scala-library.jar"/>
   <echo message="scala-library = ${scala-library}"/>
   <echo message="scala-home = ${scala-home}"/>
   <echo message="platform.bootcp = ${platform.bootcp}"/>
   <echo message="dist.apk.dir = ${dist.apk.dir}"/>
   <echo message="build.classes.dir = ${build.classes.dir}"/>
   <path id="build.classpath">
     <pathelement location="${scala-library}"   />
     <!--<pathelement location="${your.path}"   />-->
     <pathelement location="${build.classes.dir}"   />
   </path>
   <taskdef resource="scala/tools/ant/antlib.xml">
     <classpath>
       <pathelement location="${scala.home}/lib/scala-compiler.jar"   />
       <pathelement location="${scala-library}"   />
       <pathelement location="${javac.classpath}" /> 
     </classpath>
   </taskdef>
   <scalac srcdir="${src.ScalaSource.dir}" destdir="${build.classes.dir}" >
      <classpath>
       <pathelement location="/Users/development/Documents/AndroidTest/scala-library.jar"   />
       <pathelement location = "${scala-library}" />
       <pathelement location = "${file.reference.android.jar}" />
       <pathelement path="${javac.classpath}" /> 
     </classpath>
   </scalac>
   <echo message="file.reference.android.jar: ${file.reference.android.jar}"/>
   <echo message="file.reference.scala-library.jar: ${file.reference.scala-library.jar}"/>
 </target>

 <target name="-pre-jar">
        <!-- Empty placeholder for easier customization. -->
        <!-- You can override this target in the ../build.xml file. -->
 <taskdef resource="proguard/ant/task.properties"
   classpath="tools/proguard.jar" />
 <proguard>
   -injars ${scala-library}(!META-INF/MANIFEST.MF,!library.properties)
   -outjars "${build.classes.dir}/classes.min.jar"
   -libraryjars "${file.reference.android.jar}"
   -dontwarn
   -dontoptimize
   -dontobfuscate
   -keep public class * extends android.app.Activity
   -keep public class scala.xml.include.sax.Main**
 </proguard>
    </target>

我已经获得了该项目,以便它可以构建,但在我的 Android 模拟器中启动时出错(在模拟器内 Android 告诉我我的应用程序已停止不料)。

所以我的问题是:有人看到我可能做错了什么吗?有什么方法可以访问模拟器必须创建的日志吗?

谢谢

编辑:仅供参考,这是 adb logcat 的输出:

I/dalvikvm(  369): Failed resolving Lorg/me/androidtest/MainActivity; interface 35 'Lscala/ScalaObject;'
W/dalvikvm(  369): Link of class 'Lorg/me/androidtest/MainActivity;' failed
D/AndroidRuntime(  369): Shutting down VM
W/dalvikvm(  369): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime(  369): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(  369): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.me.androidtest/org.me.androidtest.MainActivity}: java.lang.ClassNotFoundException: org.me.androidtest.MainActivity in loader dalvik.system.PathClassLoader@43d02720
E/AndroidRuntime(  369):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime(  369):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime(  369):    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime(  369):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime(  369):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  369):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  369):    at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime(  369):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  369):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  369):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(  369):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(  369):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  369): Caused by: java.lang.ClassNotFoundException: org.me.androidtest.MainActivity in loader dalvik.system.PathClassLoader@43d02720
E/AndroidRuntime(  369):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
E/AndroidRuntime(  369):    at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime(  369):    at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime(  369):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime(  369):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
E/AndroidRuntime(  369):    ... 11 more
I/Process (   56): Sending signal. PID: 369 SIG: 3
I/dalvikvm(  369): threadid=7: reacting to signal 3
I/dalvikvm(  369): Wrote stack trace to '/data/anr/traces.txt'
W/ActivityManager(   56): Launch timeout has expired, giving up wake lock!

显然,这是某种类型的类加载器/类路径问题或其他问题(至少如果这是 JVM,我会这么说),但是当我查看我的 Proguard 的 jar 文件,我找到了我期望的类:scala.ScalaObject、org.me.androidtest.MainActivity 和其他一些类。

如果它对项目有帮助,则其内部的所有依赖项位于 http://philosophicalsoftware.com/AndroidTest.zip< /a>

Due to Apple's recent T+C hijinks, I've become interested in developing for Android.

Anyways, I'm trying to get a mixed-language Android 2.1 project going in Netbeans 6.8 (with the NBAndroid 0.10 plugin). The two languages being Java and Scala(2.8 head build). To give you a basic idea of what the app does right now, it's just a simple "Hello World" app.

To get this to build, I've modified the projects's build.xml file:

 <target name="-pre-compile" depends="init">
   <property name="scala-home" value="/Users/development/Applications/scala-2.8.0/build/pack"/>
   <property name="scala-library" value="/Users/development/Applications/scala-2.8.0/build/pack/lib/scala-library.jar"/>
   <echo message="scala-library = ${scala-library}"/>
   <echo message="scala-home = ${scala-home}"/>
   <echo message="platform.bootcp = ${platform.bootcp}"/>
   <echo message="dist.apk.dir = ${dist.apk.dir}"/>
   <echo message="build.classes.dir = ${build.classes.dir}"/>
   <path id="build.classpath">
     <pathelement location="${scala-library}"   />
     <!--<pathelement location="${your.path}"   />-->
     <pathelement location="${build.classes.dir}"   />
   </path>
   <taskdef resource="scala/tools/ant/antlib.xml">
     <classpath>
       <pathelement location="${scala.home}/lib/scala-compiler.jar"   />
       <pathelement location="${scala-library}"   />
       <pathelement location="${javac.classpath}" /> 
     </classpath>
   </taskdef>
   <scalac srcdir="${src.ScalaSource.dir}" destdir="${build.classes.dir}" >
      <classpath>
       <pathelement location="/Users/development/Documents/AndroidTest/scala-library.jar"   />
       <pathelement location = "${scala-library}" />
       <pathelement location = "${file.reference.android.jar}" />
       <pathelement path="${javac.classpath}" /> 
     </classpath>
   </scalac>
   <echo message="file.reference.android.jar: ${file.reference.android.jar}"/>
   <echo message="file.reference.scala-library.jar: ${file.reference.scala-library.jar}"/>
 </target>

 <target name="-pre-jar">
        <!-- Empty placeholder for easier customization. -->
        <!-- You can override this target in the ../build.xml file. -->
 <taskdef resource="proguard/ant/task.properties"
   classpath="tools/proguard.jar" />
 <proguard>
   -injars ${scala-library}(!META-INF/MANIFEST.MF,!library.properties)
   -outjars "${build.classes.dir}/classes.min.jar"
   -libraryjars "${file.reference.android.jar}"
   -dontwarn
   -dontoptimize
   -dontobfuscate
   -keep public class * extends android.app.Activity
   -keep public class scala.xml.include.sax.Main**
 </proguard>
    </target>

I've gotten the project so that it'll build, but it errors on startup in my Android Emulator(inside the emulator Android tells me my application has stopped unexpectedly).

So my questions are: Does anyone see what I may be doing wrong? And is there any way to get access to the logs that the emulator must create?

thanks

Edit: FYI, here's the output from adb logcat:

I/dalvikvm(  369): Failed resolving Lorg/me/androidtest/MainActivity; interface 35 'Lscala/ScalaObject;'
W/dalvikvm(  369): Link of class 'Lorg/me/androidtest/MainActivity;' failed
D/AndroidRuntime(  369): Shutting down VM
W/dalvikvm(  369): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime(  369): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime(  369): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.me.androidtest/org.me.androidtest.MainActivity}: java.lang.ClassNotFoundException: org.me.androidtest.MainActivity in loader dalvik.system.PathClassLoader@43d02720
E/AndroidRuntime(  369):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
E/AndroidRuntime(  369):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime(  369):    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime(  369):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime(  369):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  369):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  369):    at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime(  369):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  369):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  369):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime(  369):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime(  369):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  369): Caused by: java.lang.ClassNotFoundException: org.me.androidtest.MainActivity in loader dalvik.system.PathClassLoader@43d02720
E/AndroidRuntime(  369):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
E/AndroidRuntime(  369):    at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
E/AndroidRuntime(  369):    at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
E/AndroidRuntime(  369):    at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
E/AndroidRuntime(  369):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2409)
E/AndroidRuntime(  369):    ... 11 more
I/Process (   56): Sending signal. PID: 369 SIG: 3
I/dalvikvm(  369): threadid=7: reacting to signal 3
I/dalvikvm(  369): Wrote stack trace to '/data/anr/traces.txt'
W/ActivityManager(   56): Launch timeout has expired, giving up wake lock!

Clearly, it's some type of classloader/classpath issue or something(at least that's what I'd say if this was the JVM), but when I look inside my Proguard'd jarfile I find The classes I'd expect: scala.ScalaObject, org.me.androidtest.MainActivity, and some others.

If it helps the project with all it's dependencies made internal is located at http://philosophicalsoftware.com/AndroidTest.zip

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沫尐诺 2024-09-04 10:44:07

有人看到我在做什么吗
错了?

是的。你没有任何源代码。 :-)

有什么办法可以访问
模拟器必须的日志
创建?

我不确定 Netbeans 的内部情况,但您可以使用 adb logcat 或 DDMS 来检查日志,其中将包含......嗯......一些东西。通常,我会说“显示异常原因的 Java 堆栈跟踪”,但我不能 100% 确定 Scala 应用程序会发生什么(尽管我计划很快做一些 Scala/Android 实验)。

Does anyone see what I may be doing
wrong?

Yes. You don't have any source code. :-)

And is there any way to get access to
the logs that the emulator must
create?

I'm not sure about inside of Netbeans, but you can use adb logcat or DDMS to examine the logs, which will contain...well...something. Ordinarily, I'd say "a Java stack trace showing the cause of your exception", but I'm not 100% certain what happens with a Scala app (though I am planning on doing some Scala/Android experiments soonish).

混吃等死 2024-09-04 10:44:07

我遇到了同样的问题,终于找到了解决方案:)

在我的例子中,我没有将属性 out.dex.input.absolute.dir (在 SDK Tools r8 中)的值更改为 jar 文件由 Proguard 生成。因此,ScalaObject 接口确实不存在于 apk 文件中。

(我发现使用很棒的 apktool。)

I had the same problem and finally found the solution:)

In my case, I was not changing the value of property out.dex.input.absolute.dir (in SDK Tools r8) to jar file that was generated by Proguard. So, the ScalaObject interface was really not present in apk file.

(I discovered that using great apktool.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文