android and osgi: can they work together?

54
Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license. Android and OSGi: Can they Work Together? BJ Hargrave Senior Technical Staff Member, IBM Lotus Neil Bartlett Java Developer and Consultant

Upload: peterbuck

Post on 10-May-2015

3.586 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Android and OSGi: Can they Work Together?BJ Hargrave

Senior Technical Staff Member, IBM Lotus

Neil Bartlett

Java Developer and Consultant

Page 2: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Yes!

Page 3: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Any Questions?

Page 4: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Motivation

Page 5: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Different Models

App App

App

JVM

App

DVM

App

DVM

App

DVM

OSGi Android

Page 6: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Benefits of OSGi

Page 7: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

App AppInvoke

Cheap

Page 8: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

App App

lib lib lib lib

Possible

Page 9: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Benefits of Android

Page 10: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

App App

Safe

Page 11: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

App App

Safe

Page 12: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Finding the right granularity

Page 13: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Prior work

Page 14: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Felix on Android

Marcel Offermans(Luminis)

Karl Pauls(Luminis)

Page 15: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

http://blog.luminis.nl/luminis/entry/osgi_on_google_android_using

(repeated on last slide)

Page 16: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Our Goal

Equinox Concierge

Page 17: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

1. Concierge

Page 18: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

First step: Start Framework

Page 19: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

“Dexification”

Page 20: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

dx --dex --output=classes.dex foo.jar

aapt add foo.jar classes.dex

Page 21: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Code changes Required

Page 22: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Page 23: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Next Step: Adding a Bundle

Page 24: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

ClassLoader.defineClass()does not work

Page 25: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Use android.dalvik.DexFile

Page 26: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

private final DexFile df; DexHelper(File file) throws Exception { df = new DexFile(file);}

Class defineClass(ClassLoader cl, String name) { String dexName = name.replace('.', '/'); try {

Class c = df.loadClass(dexName, cl); return c;

} catch (Exception e) { // log error return null; }}

Page 27: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Patch Limitations

Simple bundle classpath only, i.e. Bundle-ClassPath: .

No nested JARs

No directory bundles

Page 28: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Android doesn’t like this:

ClassLoader.loadClass(clazz, true)

‘true’ triggers ClassLoader.resolveClass(), which fails

=> call ClassLoader.loadClass(clazz)

‘false’ is the default

Page 29: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Success!

Page 30: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

DEMO

Page 31: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

2. Equinox

Page 32: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

First Step: Start Framework

Page 33: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Somewhat Harder

Page 34: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Equinox uses CodeSource to configure some properties

On Android, ProtectionDomain is null so no CodeSource

=> Supply properties explicitly

Page 35: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

-Dosgi.framework=file:/data/equinoxorg.eclipse.osgi_3.4.0.jar

-Dosgi.install.area=file:/data/equinox

Page 36: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

ClassLoader.getResource() is used to return list of Hook configuration property files

Android always return an empty enum

=> Manually list hooks in config.ini

Page 37: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

osgi.hook.configurators=org.eclipse.osgi.internal.baseadaptor.BaseHookConfigurator,org.eclipse.core.runtime.internal.adaptor.EclipseLogHook,org.eclipse.core.runtime.internal.adaptor.EclipseLazyStarter,org.eclipse.core.runtime.internal.adaptor.EclipseStorageHook

Page 38: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Strange VerifyError on a framework internal class

=> Turn off the verifier

Is this a dexifier bug?

Page 39: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Page 40: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Next Step: Adding a Bundle

Page 41: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Same need for DexHelper

Page 42: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Same Limitations

Page 43: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

boot

ext

app

bundle bundlebundle

Frameworkjava.*

??

Page 44: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

dummy

java.*

boot

ext

app

bundle bundlebundle

Framework

Page 45: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Cannot find java.lang.Object!

Page 46: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

-Dosgi.parentClassloader=ext

Page 47: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

boot

ext

app

bundle bundlebundle

Frameworkjava.*

Page 48: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Success!

Page 49: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

DEMO

Page 50: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Possible Next Steps

A proper hook for dex file loading

Full Bundle-ClassPath support

JIT dexification of JARs in the hook?

Equinox incubator?

Page 51: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Getting Started

All changes available as patches against Concierge, Equinox

Subversion repository:

http://www.osgi.org/svn/public/trunk/eclipsecon/2008/androidosgi

Page 52: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

ProSyst

http://www.adon-line.de/kunden/prosystBlog/?p=24

Page 53: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Links

Felix on Android

http://blog.luminis.nl/luminis/entry/osgi_on_google_android_using

Our Repository:

http://www.osgi.org/svn/public/trunk/eclipsecon/2008/androidosgi

ProSyst Announcement:

http://www.adon-line.de/kunden/prosystBlog/?p=24

Page 54: Android and OSGi: Can they Work Together?

Android and OSGi | Copyright © Neil Bartlett and IBM Corp., 2007-2008. All rights reserved. Source code in this presentation is made available under the EPL, v1.0, remainder of the presentation is licensed under Creative Commons Att. Nc Nd 2.5 license.

Legal Notices

• IBM and the IBM logo are trademarks or registered trademarks of IBM Corporation, in the United States, other countries or both.

• Java and all Java-based marks, among others, are trademarks or registered trademarks of Sun Microsystems in the United States, other countries or both.

• Eclipse and the Eclipse logo are trademarks of Eclipse Foundation, Inc.

• Other company, product and service names may be trademarks or service marks of others.

• THE INFORMATION DISCUSSED IN THIS PRESENTATION IS PROVIDED FOR INFORMATIONAL PURPOSES ONLY. WHILE EFFORTS WERE MADE TO VERIFY THE COMPLETENESS AND ACCURACY OF THE INFORMATION, IT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, AND IBM SHALL NOT BE RESPONSIBLE FOR ANY DAMAGES ARISING OUT OF THE USE OF, OR OTHERWISE RELATED TO, SUCH INFORMATION. ANY INFORMATION CONCERNING IBM'S PRODUCT PLANS OR STRATEGY IS SUBJECT TO CHANGE BY IBM WITHOUT NOTICE.