2

I'm trying to create and test a simple dummy Android application written in Scala without the ProGuard step (useProguard := false).


I have pushed scala library to the /system/framework:
/system/framework/scala-library-2.9.1.jar

and a permissions file to /system/etc/permissions:
/system/etc/permissions/scala-library-2.9.1.xml


The contents of permissions xml:

<?xml version="1.0" encoding="utf-8"?>

<permissions>
    <library
        name="scala-library-2.9.1"
        file="/system/framework/scala-library-2.9.1.jar"
    />
</permissions>

Here is my MainActivity.scala:

package com.google.summer

import _root_.android.app.Activity
import _root_.android.os.Bundle
import _root_.android.graphics.Typeface
import _root_.android.text.Html

class MainActivity extends Activity with TypedActivity {
    override def onCreate(bundle: Bundle) {
        super.onCreate(bundle)
        setContentView(R.layout.main)

        // my dummy code here

    }
}

Here is my AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.summer">

    <application
        android:icon="@drawable/android:star_big_on"
        android:label="@string/app_name"
        android:debuggable="true">

        <activity android:label="@string/app_name" android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <uses-library android:name="scala-library-2.9.1" />
    </application>

    <uses-sdk android:minSdkVersion="10"/>
</manifest>

I managed to install it on my device without using ProGuard, however, when I try to run it, I get the following exception (captured using logcat):

dalvikvm   I  Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
dalvikvm   I  Failed resolving Lcom/google/summer/TypedViewHolder; interface 48 'Lscala/ScalaObject;'
dalvikvm   W  Link of class 'Lcom/google/summer/TypedViewHolder;' failed
dalvikvm   I  Failed resolving Lcom/google/summer/TypedActivityHolder; interface 30 'Lcom/google/summer/TypedViewHolder;'
dalvikvm   W  Link of class 'Lcom/google/summer/TypedActivityHolder;' failed
dalvikvm   I  Failed resolving Lcom/google/summer/TypedActivity; interface 19 'Lcom/google/summer/TypedActivityHolder;'
dalvikvm   W  Link of class 'Lcom/google/summer/TypedActivity;' failed
dalvikvm   I  Failed resolving Lcom/google/summer/MainActivity; interface 18 'Lcom/google/summer/TypedActivity;'
dalvikvm   W  Link of class 'Lcom/google/summer/MainActivity;' failed


FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.google.summer/com.google.summer.MainActivity}: java.lang.ClassNotFoundException: com.google.summer.MainActivity in loader dalvik.system.PathClassLoader[/system/framework/scala-library-2.9.1.jar:/data/app/com.google.summer-1.apk]
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1680)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
     at android.app.ActivityThread.access$1500(ActivityThread.java:123)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:123)
     at android.app.ActivityThread.main(ActivityThread.java:3835)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:507)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
     at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.google.summer.MainActivity in loader dalvik.system.PathClassLoader[/system/framework/scala-library-2.9.1.jar:/data/app/com.google.summer-1.apk]
     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1672)
     ... 11 more
  Force finishing activity com.google.summer/.MainActivity

Does anyone know where the error might be and what to do to resolve it?

Thanks in advance :D

BTW, could it be that there is a problem with scala library that was pushed?
Logcat says it cannot find scala.ScalaObject but it is present in the jar I pushed.

ioreskovic
  • 5,531
  • 5
  • 39
  • 70
  • Does it work in the emulator or does it fail there aswell? – Emil L Jul 26 '12 at 09:46
  • Well, since I cannot root the emulator nor push Scala library to emulator, there is no way that will work there, but that's isn't even the intention. – ioreskovic Jul 26 '12 at 09:48
  • I see I missed that you were adding Scala not as a library for your app, but as a system wide library. Does it work to deploy a regular java app that you create? Are you installing the app on your SD-card (seems to be a few that have had issues with that)? – Emil L Jul 26 '12 at 10:18
  • Yes, regular deplyment using ProGuard where the library is packed together with the app works. And no, my app is installed in /system/app, not on SD card. – ioreskovic Jul 26 '12 at 10:26
  • You could try setting `android:required` to true and see if the App is allowed on the device see: http://developer.android.com/guide/topics/manifest/uses-library-element.html That way you will at least know if the scala library can be found. – Emil L Jul 26 '12 at 10:45
  • I added a few more lines to the exception section – ioreskovic Jul 26 '12 at 11:05
  • How are you building your rom? Is the scala library included during the build? Seems to me that your Scala jar is not added correctly. – Emil L Jul 26 '12 at 12:21
  • I'm not building a rom. I'm remounting, pushing scala library and permissions and rebooting the device. – ioreskovic Jul 26 '12 at 12:29
  • Ok! Then what you want is not possible. You can't add new external libraries (i.e. that is shared between apps) at will to devices. You will need to include the scala jar in every app you develop. – Emil L Jul 26 '12 at 12:36
  • Ah, thank you very much :D You mightr want to post that as an answer so I can give you well-deserved props for trying :D – ioreskovic Jul 26 '12 at 12:39

1 Answers1

2

You can't add new external libraries (i.e. that is shared between apps) at will to devices. You will need to include the scala jar in every app you create.

It could be done by creating a custom rom with Scala available on it, but then everyone who wanted to run your app would need that custom rom. Not very practical :)

Emil L
  • 20,219
  • 3
  • 44
  • 65