当它在具有单独包的外部库中时无法启动服务

时间:2016-05-18 12:13:36

标签: android android-studio

以下是开发环境

compileSdkVersion 22 buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "techsys.service.app.serverhostapp"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0" }

创建了一个具有粘性服务的android库,该库包含在一个Android应用程序中。内部库中的此服务在应用程序清单文件中声明为

    <service
        android:name="techsys.service.app.appserver.uniqueservice"
        android:enabled="true"
        android:exported="true"

        >
    </service>

此服务在

等应用程序中启动
context.bindService(new Intent(context, uniqueservice.class), conn, Context.BIND_AUTO_CREATE);

此服务aidl接口文件包含在具有库包文件夹路径的应用程序中。

编译和构建成功但看起来像是一些基本问题。

注意:如果包含没有库的服务,那么它可以正常工作。

这会出现以下错误: -

    05-18 17:27:52.900 27195-27195/techsys.service.app.serverhostapp D/MainActivity: onCreate
05-18 17:27:52.900 27195-27195/techsys.service.app.serverhostapp D/MainActivity: uniqueuservice bindService()
05-18 17:27:52.900 27195-27195/techsys.service.app.serverhostapp D/MainActivity: bind uniqueuservice Service
05-18 17:27:52.954 27195-27195/techsys.service.app.serverhostapp D/MainActivity: onStart
05-18 17:27:52.955 27195-27195/techsys.service.app.serverhostapp D/AppTracker: App Event: start
05-18 17:27:52.987 27195-27195/techsys.service.app.serverhostapp D/AbstractTracker: Event success
05-18 17:27:52.988 27195-27195/techsys.service.app.serverhostapp D/ThreadedRenderer: mThreadGroupCpuId 3 mRenderThreadCpuId 0 affinity
05-18 17:27:52.994 27195-27195/techsys.service.app.serverhostapp I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@3d0c23f6 time:8758912
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art: Incompatible structural change detected: Structural change of techsys.service.app.appserver.Iuniqueservice$Stub is hazardous (/data/data/techsys.service.app.serverhostapp/cache/slice-exploded-aar-appserver-debug_e627187da9024749a2416db2406342c5fa9d214e-classes.dex at compile time, /data/data/techsys.service.app.serverhostapp/cache/slice-slice_9-classes.dex at runtime): Direct method count off: 2 vs 4
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art: Ltechsys/service/app/appserver/Iuniqueservice$Stub; (Compile time):
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:  Static fields:
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   Ljava/lang/String; DESCRIPTOR
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   I TRANSACTION_multiple
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:  Instance fields:
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:  Direct methods:
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   <init>()V
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   asInterface(Landroid/os/IBinder;)Ltechsys/service/app/appserver/Iuniqueservice;
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:  Virtual methods:
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   asBinder()Landroid/os/IBinder;
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art: Ltechsys/service/app/appserver/Iuniqueservice$Stub; (Runtime):
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:  Static fields:
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   Lcom/android/tools/fd/runtime/IncrementalChange; $change
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   Ljava/lang/String; DESCRIPTOR
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   I TRANSACTION_multiple
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:  Instance fields:
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:  Direct methods:
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   <init>()V
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   <init>([Ljava/lang/Object;Lcom/android/tools/fd/runtime/InstantReloadException;)V
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   access$super(Ltechsys/service/app/appserver/Iuniqueservice$Stub;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   asInterface(Landroid/os/IBinder;)Ltechsys/service/app/appserver/Iuniqueservice;
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:  Virtual methods:
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   asBinder()Landroid/os/IBinder;
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote W/art:   onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
05-18 17:27:53.020 27762-27762/techsys.service.app.serverhostapp:remote D/AndroidRuntime: Shutting down VM


                                                                                              --------- beginning of crash
05-18 17:27:53.021 27762-27762/techsys.service.app.serverhostapp:remote E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                              Process: techsys.service.app.serverhostapp:remote, PID: 27762
                                                                                              java.lang.IncompatibleClassChangeError: Structural change of techsys.service.app.appserver.Iuniqueservice$Stub is hazardous (/data/data/techsys.service.app.serverhostapp/cache/slice-exploded-aar-appserver-debug_e627187da9024749a2416db2406342c5fa9d214e-classes.dex at compile time, /data/data/techsys.service.app.serverhostapp/cache/slice-slice_9-classes.dex at runtime): Direct method count off: 2 vs 4
                                                                                              Ltechsys/service/app/appserver/Iuniqueservice$Stub; (Compile time):
                                                                                               Static fields:
                                                                                                Ljava/lang/String; DESCRIPTOR
                                                                                                I TRANSACTION_multiple
                                                                                               Instance fields:
                                                                                               Direct methods:
                                                                                                <init>()V
                                                                                                asInterface(Landroid/os/IBinder;)Ltechsys/service/app/appserver/Iuniqueservice;
                                                                                               Virtual methods:
                                                                                                asBinder()Landroid/os/IBinder;
                                                                                                onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
                                                                                              Ltechsys/service/app/appserver/Iuniqueservice$Stub; (Runtime):
                                                                                               Static fields:
                                                                                                Lcom/android/tools/fd/runtime/IncrementalChange; $change
                                                                                                Ljava/lang/String; DESCRIPTOR
                                                                                                I TRANSACTION_multiple
                                                                                               Instance fields:
                                                                                               Direct methods:
                                                                                                <init>()V
                                                                                                <init>([Ljava/lang/Object;Lcom/android/tools/fd/runtime/InstantReloadException;)V
                                                                                                access$super(Ltechsys/service/app/appserver/Iuniqueservice$Stub;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;
                                                                                                asInterface(Landroid/os/IBinder;)Ltechsys/service/app/appserver/Iuniqueservice;
                                                                                               Virtual methods:
                                                                                                asBinder()Landroid/os/IBinder;
                                                                                                onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
                                                                                               (declaration of 'techsys.service.app.appserver.uniqueservice$1' appears in /data/data/techsys.service.app.serverhostapp/files/instant-run/dex/slice-exploded-aar-appserver-debug_e627187da9024749a2416db2406342c5fa9d214e-classes.dex)
                                                                                                  at dalvik.system.DexFile.defineClassNative(Native Method)
                                                                                                  at dalvik.system.DexFile.defineClass(DexFile.java:226)
                                                                                                  at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
                                                                                                  at dalvik.system.DexPathList.findClass(DexPathList.java:321)
                                                                                                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
                                                                                                  at com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader.findClass(IncrementalClassLoader.java:90)
                                                                                                  at com.android.tools.fd.runtime.IncrementalClassLoader.findClass(IncrementalClassLoader.java:62)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                                                                  at techsys.service.app.appserver.uniqueservice.<init>(uniqueservice.java:13)
                                                                                                  at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                                                  at java.lang.Class.newInstance(Class.java:1606)
                                                                                                  at android.app.ActivityThread.handleCreateService(ActivityThread.java:2780)
                                                                                                  at android.app.ActivityThread.access$1900(ActivityThread.java:155)
                                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1406)
                                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                                  at android.os.Looper.loop(Looper.java:139)
                                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5298)
                                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                                  at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
                                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
05-18 17:27:53.024 27762-27762/techsys.service.app.serverhostapp:remote D/AppTracker: App Event: crash
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art: Incompatible structural change detected: Structural change of techsys.service.app.appserver.Iuniqueservice$Stub is hazardous (/data/data/techsys.service.app.serverhostapp/cache/slice-exploded-aar-appserver-debug_e627187da9024749a2416db2406342c5fa9d214e-classes.dex at compile time, /data/data/techsys.service.app.serverhostapp/cache/slice-slice_9-classes.dex at runtime): Direct method count off: 2 vs 4
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art: Ltechsys/service/app/appserver/Iuniqueservice$Stub; (Compile time):
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:  Static fields:
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   Ljava/lang/String; DESCRIPTOR
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   I TRANSACTION_multiple
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:  Instance fields:
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:  Direct methods:
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   <init>()V
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   asInterface(Landroid/os/IBinder;)Ltechsys/service/app/appserver/Iuniqueservice;
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:  Virtual methods:
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   asBinder()Landroid/os/IBinder;
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art: Ltechsys/service/app/appserver/Iuniqueservice$Stub; (Runtime):
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:  Static fields:
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   Lcom/android/tools/fd/runtime/IncrementalChange; $change
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   Ljava/lang/String; DESCRIPTOR
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   I TRANSACTION_multiple
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:  Instance fields:
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:  Direct methods:
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   <init>()V
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   <init>([Ljava/lang/Object;Lcom/android/tools/fd/runtime/InstantReloadException;)V
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   access$super(Ltechsys/service/app/appserver/Iuniqueservice$Stub;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   asInterface(Landroid/os/IBinder;)Ltechsys/service/app/appserver/Iuniqueservice;
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:  Virtual methods:
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   asBinder()Landroid/os/IBinder;
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote W/art:   onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
05-18 17:27:54.164 27803-27803/techsys.service.app.serverhostapp:remote D/AndroidRuntime: Shutting down VM
05-18 17:27:54.166 27803-27803/techsys.service.app.serverhostapp:remote E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                              Process: techsys.service.app.serverhostapp:remote, PID: 27803
                                                                                              java.lang.IncompatibleClassChangeError: Structural change of techsys.service.app.appserver.Iuniqueservice$Stub is hazardous (/data/data/techsys.service.app.serverhostapp/cache/slice-exploded-aar-appserver-debug_e627187da9024749a2416db2406342c5fa9d214e-classes.dex at compile time, /data/data/techsys.service.app.serverhostapp/cache/slice-slice_9-classes.dex at runtime): Direct method count off: 2 vs 4
                                                                                              Ltechsys/service/app/appserver/Iuniqueservice$Stub; (Compile time):
                                                                                               Static fields:
                                                                                                Ljava/lang/String; DESCRIPTOR
                                                                                                I TRANSACTION_multiple
                                                                                               Instance fields:
                                                                                               Direct methods:
                                                                                                <init>()V
                                                                                                asInterface(Landroid/os/IBinder;)Ltechsys/service/app/appserver/Iuniqueservice;
                                                                                               Virtual methods:
                                                                                                asBinder()Landroid/os/IBinder;
                                                                                                onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
                                                                                              Ltechsys/service/app/appserver/Iuniqueservice$Stub; (Runtime):
                                                                                               Static fields:
                                                                                                Lcom/android/tools/fd/runtime/IncrementalChange; $change
                                                                                                Ljava/lang/String; DESCRIPTOR
                                                                                                I TRANSACTION_multiple
                                                                                               Instance fields:
                                                                                               Direct methods:
                                                                                                <init>()V
                                                                                                <init>([Ljava/lang/Object;Lcom/android/tools/fd/runtime/InstantReloadException;)V
                                                                                                access$super(Ltechsys/service/app/appserver/Iuniqueservice$Stub;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/Object;
                                                                                                asInterface(Landroid/os/IBinder;)Ltechsys/service/app/appserver/Iuniqueservice;
                                                                                               Virtual methods:
                                                                                                asBinder()Landroid/os/IBinder;
                                                                                                onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
                                                                                               (declaration of 'techsys.service.app.appserver.uniqueservice$1' appears in /data/data/techsys.service.app.serverhostapp/files/instant-run/dex/slice-exploded-aar-appserver-debug_e627187da9024749a2416db2406342c5fa9d214e-classes.dex)
                                                                                                  at dalvik.system.DexFile.defineClassNative(Native Method)
                                                                                                  at dalvik.system.DexFile.defineClass(DexFile.java:226)
                                                                                                  at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
                                                                                                  at dalvik.system.DexPathList.findClass(DexPathList.java:321)
                                                                                                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
                                                                                                  at com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader.findClass(IncrementalClassLoader.java:90)
                                                                                                  at com.android.tools.fd.runtime.IncrementalClassLoader.findClass(IncrementalClassLoader.java:62)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                                                                  at techsys.service.app.appserver.uniqueservice.<init>(uniqueservice.java:13)
                                                                                                  at java.lang.reflect.Constructor.newInstance(Native Method)
                                                                                                  at java.lang.Class.newInstance(Class.java:1606)
                                                                                                  at android.app.ActivityThread.handleCreateService(ActivityThread.java:2780)
                                                                                                  at android.app.ActivityThread.access$1900(ActivityThread.java:155)
                                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1406)
                                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                                  at android.os.Looper.loop(Looper.java:139)
                                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5298)
                                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                                  at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:950)
                                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:745)
05-18 17:27:54.169 27803-27803/techsys.service.app.serverhostapp:remote D/AppTracker: App Event: crash

1 个答案:

答案 0 :(得分:0)

图书馆中的服务,它被绑定或由像

这样的应用程序启动
context.bindService(new Intent(context, uniqueservice.class), conn, Context.BIND_AUTO_CREATE);

然后它应该是直接链接的,不需要添加导致问题的aidl接口。

一旦删除了aidl接口,它就会干净利落地启动,如果任何其他第三方应用程序想要绑定,那么它们可以包含aidl接口和绑定服务。

只需将进程更新为:远程主机或主应用程序清单文件,如

    <service
        android:name="techsys.service.app.appserver.uniqueservice"
        android:enabled="true"
        android:exported="true"
        android:process=":remote"
        >
    </service>
相关问题