[sip-comm-dev] Porting SIP communicator on Android - Activator start error :BundleException


#1

I am trying to port the Sip communicator application to android. This is
done by launching felix from the android activity. The other bundles are
installed by reading the bundles a Inputstream from the res/raw. The bundles
are getting installed.
The bundle.start() function is successful for bundles, which doesn't have
the Bundle-Activator constant in the manifest file. But if the
Bundle-Activator is present, the activator class fails to get loaded and
hence the bundle.start() fails with
BundleException - unable to load this type of class and a reference to the
defineClass function of the Dalvik vm.

I tried to use the luminis solution for this as below. Please see my
comments in the code

public class DalvikClassLoader {

    static final Constructor m_dexFileClassConstructor;
    private static final Method m_dexFileClassLoadClass;

static
{
    Constructor dexFileClassConstructor = null;
    Method dexFileClassLoadClass = null;
    try
    {
        Class dexFileClass = Class.forName("android.dalvik.DexFile");
//Padma - First it failed here saying ClassNotFound exception. Then I
changed it "dalvil.system.DexFile" and this step was through.

        dexFileClassConstructor = dexFileClass.getConstructor(
            new Class[] { java.io.File.class });
        dexFileClassLoadClass = dexFileClass.getMethod("loadClass",
            new Class[] { String.class, ClassLoader.class });
    }
    catch (Exception ex)
    {
        dexFileClassConstructor = null;
        dexFileClassLoadClass = null;
    }
    m_dexFileClassConstructor = dexFileClassConstructor;
    m_dexFileClassLoadClass = dexFileClassLoadClass;
}

//Padma - I called this function after installing the bundle and before
starting the bundle as
//getDexFileClass(activatorClassName, ClassLoader.getSystemClassLoader)
// where the activatorClassName =
(String)bundle.getHeaders().get("Bundle-Activator");

private Object m_dexFile = null;

public synchronized Class getDexFileClass(String name, ClassLoader loader)
    throws Exception
{
    if (m_dexFile == null)
    {
        if ((m_dexFileClassConstructor != null) &&
              (m_dexFileClassLoadClass != null))
        {
            m_dexFile = m_dexFileClassConstructor.newInstance(
                new Object[] { m_file });
//It failed at m_file. So I tried to use the following:
// classes.dex - failed.
// /data/app/net.java.sip.communicator.android.apk - fails with unable to
open DEX filenull

//Because of these errors, I changed the constructor in the static block to
//dexFileClassConstructor = dexFileClass.getConstructor(
// new Class[] { java.lang.String.class });

//And Changed the m_dexFile creation as below:
//m_dexFile = m_dexFileClassConstructor.newInstance(
// new Object[] {
"/data/app/net.java.sip.communicator.android.apk" });

        }
        else
        {
            return null;
        }
    }

    return (Class) m_dexFileClassLoadClass.invoke(m_dexFile,
        new Object[] { name.replace('.','/'), loader });

//This returns null again. Whereas the m_dexFile value is
dalvik.system.DexFile@434ae908
}

I tried to load the bundles given by luminis as well, but didn't understand
how to load it dynamically.I am terribly confused on what's going wrong and
stuck with this for the past couple of days. Can somebody help me on this.


#2

Hi Emp,

The effort to port SIP Communicator to Android is at
http://sc-android.dev.java.net. Did you try their mailing lists first?

Regards,
Lubo

···

On Wed, Apr 8, 2009 at 10:57 AM, Emp Augur <augursys.emp@gmail.com> wrote:

I am trying to port the Sip communicator application to android. This is
done by launching felix from the android activity. The other bundles are
installed by reading the bundles a Inputstream from the res/raw. The bundles
are getting installed.
The bundle.start() function is successful for bundles, which doesn't have
the Bundle-Activator constant in the manifest file. But if the
Bundle-Activator is present, the activator class fails to get loaded and
hence the bundle.start() fails with
BundleException - unable to load this type of class and a reference to the
defineClass function of the Dalvik vm.

I tried to use the luminis solution for this as below. Please see my
comments in the code

public class DalvikClassLoader {

static final Constructor m\_dexFileClassConstructor;
private static final Method m\_dexFileClassLoadClass;

static
{
Constructor dexFileClassConstructor = null;
Method dexFileClassLoadClass = null;
try
{
Class dexFileClass = Class.forName("android.dalvik.DexFile");
//Padma - First it failed here saying ClassNotFound exception. Then I
changed it "dalvil.system.DexFile" and this step was through.

    dexFileClassConstructor = dexFileClass\.getConstructor\(
        new Class\[\] \{ java\.io\.File\.class \}\);
    dexFileClassLoadClass = dexFileClass\.getMethod\(&quot;loadClass&quot;,
        new Class\[\] \{ String\.class, ClassLoader\.class \}\);
\}
catch \(Exception ex\)
\{
    dexFileClassConstructor = null;
    dexFileClassLoadClass = null;
\}
m\_dexFileClassConstructor = dexFileClassConstructor;
m\_dexFileClassLoadClass = dexFileClassLoadClass;

}

//Padma - I called this function after installing the bundle and before
starting the bundle as
//getDexFileClass(activatorClassName, ClassLoader.getSystemClassLoader)
// where the activatorClassName =
(String)bundle.getHeaders().get("Bundle-Activator");

private Object m_dexFile = null;

public synchronized Class getDexFileClass(String name, ClassLoader loader)
throws Exception
{
if (m_dexFile == null)
{
if ((m_dexFileClassConstructor != null) &&
(m_dexFileClassLoadClass != null))
{
m_dexFile = m_dexFileClassConstructor.newInstance(
new Object[] { m_file });
//It failed at m_file. So I tried to use the following:
// classes.dex - failed.
// /data/app/net.java.sip.communicator.android.apk - fails with unable to
open DEX filenull

//Because of these errors, I changed the constructor in the static block to
//dexFileClassConstructor = dexFileClass.getConstructor(
// new Class[] { java.lang.String.class });

//And Changed the m_dexFile creation as below:
//m_dexFile = m_dexFileClassConstructor.newInstance(
// new Object[] {
"/data/app/net.java.sip.communicator.android.apk" });

    \}
    else
    \{
        return null;
    \}
\}

return \(Class\) m\_dexFileClassLoadClass\.invoke\(m\_dexFile,
    new Object\[\] \{ name\.replace\(&#39;\.&#39;,&#39;/&#39;\), loader \}\);

//This returns null again. Whereas the m_dexFile value is
dalvik.system.DexFile@434ae908
}

I tried to load the bundles given by luminis as well, but didn't understand
how to load it dynamically.I am terribly confused on what's going wrong and
stuck with this for the past couple of days. Can somebody help me on this.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@sip-communicator.dev.java.net
For additional commands, e-mail: dev-help@sip-communicator.dev.java.net