Hi, I had posted this question earlier in the Android-Beginners list but didn't get any response :( Saw this thread here and thought of trying my luck again!
Can someone help me with the steps to export a service to another android application? I have created a service and defined an interface which is exposed by the service. I want to be able to get a reference to this interface in another android application. package scratch.service; Service: DbService Interface: DbServiceInterface (aidl filename is DbServiceInterface.aidl) In the AndroidMainfest.xml for the Service: I have these lines: --- <permission android:name="scratch.permission.DB_SERVICE_KEY" android:label="DbServicePermission" android:description="@string/perm_desc" android:protectionLevel="dangerous"/> <uses-permission android:name="scratch.application.permission.DB_SERVICE_KEY"/> <application android:label="@string/app_name"> <!-- Export this service so that it can be used --> <service android:name=".DbService" android:exported="true" android:enabled="true" android:permission="scratch.permission.DB_SERVICE_KEY"> <intent-filter> <action android:name="MyDbService" /> </intent-filter> </service> --- Now, moving onto the the client application that uses the Service: package scratch.activity Activity: DbActivity In the AndroidMainfest.xml for the Activity: --- <uses-permission android:name="scratch.permission.DB_SERVICE_KEY" /> <application android:label="@string/app_name"> <activity android:name=".DbActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> --- I have imported scratch.service.DbServiceInterface in the source-file for the Activity but while building I used to get: --- compile: [javac] Compiling 2 source files to /home/rohan/workspace/projects/ android/MyDatabaseActivity/bin/classes [javac] /home/rohan/workspace/projects/android/MyDatabaseActivity/ src/scratch/activity/DbActivity.java:17: cannot find symbol [javac] symbol : class DbServiceInterface [javac] location: package scratch.service [javac] import scratch.service.DbServiceInterface; [javac] ^ [javac] /home/rohan/workspace/projects/android/MyDatabaseActivity/ src/scratch/activity/DbActivity.java:22: cannot find symbol [javac] symbol : class DbServiceInterface [javac] location: class scratch.activity.DbActivity [javac] private DbServiceInterface refService = null; [javac] ^ [javac] /home/rohan/workspace/projects/android/MyDatabaseActivity/ src/scratch/activity/DbActivity.java:110: package DbServiceInterface does not exist [javac] refService = DbServiceInterface.Stub.asInterface(service); [javac] ^ [javac] 3 errors --- To overcome this, I used: 'ant -libs <path-to-classes dir for the service>' Build errors disappear but while starting the Activity, I get: 01-09 12:05:22.577: INFO/ActivityManager(52): Starting activity: Intent { action=android.intent.action.MAIN categories= {android.intent.category.LAUNCHER} flags=0x10200000 comp= {scratch.activity/scratch.activity.DbActivity} } 01-09 12:05:22.978: INFO/ActivityManager(52): Start proc scratch.activity for activity scratch.activity/.DbActivity: pid=1613 uid=10018 gids={} 01-09 12:05:23.117: INFO/jdwp(1613): received file descriptor 20 from ADB 01-09 12:05:24.008: WARN/dalvikvm(1613): VFY: unable to find class referenced in signature (Lscratch/service/DbServiceInterface;) 01-09 12:05:24.047: WARN/dalvikvm(1613): VFY: unable to resolve interface method 61: Lscratch/service/DbServiceInterface;.getNames () [Ljava/lang/String; 01-09 12:05:24.057: WARN/dalvikvm(1613): VFY: rejecting opcode 0x72 at 0x0012 01-09 12:05:24.067: WARN/dalvikvm(1613): VFY: rejected Lscratch/ activity/DbActivity$3;.onClick (Landroid/view/View;)V 01-09 12:05:24.067: WARN/dalvikvm(1613): Verifier rejected class Lscratch/activity/DbActivity$3; 01-09 12:05:24.087: DEBUG/AndroidRuntime(1613): Shutting down VM 01-09 12:05:24.087: WARN/dalvikvm(1613): threadid=3: thread exiting with uncaught exception (group=0x40010e28) 01-09 12:05:24.177: ERROR/AndroidRuntime(1613): Uncaught handler: thread main exiting due to uncaught exception 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): java.lang.VerifyError: scratch.activity.DbActivity$3 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at scratch.activity.DbActivity.<init>(DbActivity.java:53) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at java.lang.Class.newInstance(Native Method) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at android.app.Instrumentation.newActivity(Instrumentation.java:1096) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2060) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2156) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at android.app.ActivityThread.access$1800(ActivityThread.java:112) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at android.os.Handler.dispatchMessage(Handler.java:88) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at android.os.Looper.loop(Looper.java:123) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at android.app.ActivityThread.main(ActivityThread.java:3742) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at java.lang.reflect.Method.invokeNative(Native Method) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at java.lang.reflect.Method.invoke(Method.java:515) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:739) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) 01-09 12:05:24.257: ERROR/AndroidRuntime(1613): at dalvik.system.NativeStart.main(Native Method) 01-09 12:05:24.437: INFO/Process(52): Sending signal. PID: 1613 SIG: 3 01-09 12:05:24.569: INFO/dalvikvm(1613): threadid=7: reacting to signal 3 01-09 12:05:24.858: INFO/dalvikvm(1613): Wrote stack trace to '/data/ anr/traces.txt' Please let me know why: [1] VerifyException(s) are thrown [2] what more I need to do to use a service across Andy Apps I read earlier that we need to compile the aidl in both the packages. So my question is: if tomorrow someone else wants to use a service written by me, does he have to include the aidl that I write while building his apk? In the above steps does 'ant- libs' take care of this? I am still confused! Thanks! Rohan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---