(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 code:
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();
}
}
}
app build :
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' }