2017-08-14 57 views
0
(declaration of 'com.google.protobuf.UnknownFieldSet$Parser' appears in /data/data/probuff.cmcm.com.protobuftest/files/instant-run/dex/slice-protobuf-java-3.3.0_337abc31829bde926038696b7f238f11a5b7c8a2-classes.dex) 
                        at dalvik.system.DexFile.defineClassNative(Native Method) 
                        at dalvik.system.DexFile.defineClass(DexFile.java:296) 
                        at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:289) 
                        at dalvik.system.DexPathList.findClass(DexPathList.java:418) 
                        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:380) 
                        at java.lang.ClassLoader.loadClass(ClassLoader.java:367) 
                        at java.lang.ClassLoader.loadClass(ClassLoader.java:367) 
                        at java.lang.ClassLoader.loadClass(ClassLoader.java:312) 
                        at com.google.protobuf.UnknownFieldSet.<clinit>(UnknownFieldSet.java:1037) 
                        at com.google.protobuf.GeneratedMessageV3.<init>(GeneratedMessageV3.java:88) 
                        at mayday.Service$Location.<init>(Service.java:0) 
                        at mayday.Service$Location.<clinit>(Service.java:7970) 
                        at probuff.cmcm.com.protobuftest.MainActivity.testProbuf(MainActivity.java:21) 
                        at probuff.cmcm.com.protobuftest.MainActivity.onCreate(MainActivity.java:16) 
                        at android.app.Activity.performCreate(Activity.java:6679) 
                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) 
                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
                        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                        at android.os.Looper.loop(Looper.java:154) 
                        at android.app.ActivityThread.main(ActivityThread.java:6119) 
                        at java.lang.reflect.Method.invoke(Native Method) 
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 

的Android代碼:java.lang.IncompatibleClassChangeError:com.google.protobuf.AbstractParser的結構變化是有害

public class MainActivity extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
      testProbuf(); 


} 
private void testProbuf(){ 
    Service.Location.Builder builder = Service.Location.newBuilder(); 
    builder.setAccuracy(1); 
    builder.setProvider("apple"); 
    byte[] bytes= builder.build().toByteArray(); 
    try { 
     Service.Location location= Service.Location.parseFrom(bytes); 
     System.out.println("test accuracy="+location.getAccuracy()+" provider="+location.getProvider()); 
    } catch (InvalidProtocolBufferException e) { 
     e.printStackTrace(); 
    } 


} 

}

應用構建:

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.google.protobuf:protobuf-java:3.3.0' compile 'io.grpc:grpc-okhttp:1.4.0' compile 'io.grpc:grpc-protobuf-lite:1.4.0' compile 'io.grpc:grpc-stub:1.4.0' }

+0

,問題是???請更具體..你想實現什麼等等,並觀看格式.. –

+0

我只是想解決崩潰,謝謝 – apple

+0

這是發生在調試?或什麼時候? –

回答

0

作爲我在評論中寫道,我知道grpc已經包含了更新版本的protobuf(3.3.1)。所以,你應該可嘗試排除包含在你的gradle這個文件中使用exclude(module: 'com.google.protobuf') GRPC protobuf的版本,或者你可以在增加你的版本3.3.1:

compile 'com.google.protobuf:protobuf-java:3.3.1'