GeorgeYang'Blog

my technology blog

android studio使用导入百度推送出现errorcode=10101解决

阅读:979 创建时间:16-01-10 09:30:09 tags:androidstudio,baidupush

出现这个原因主要是因为以下两个原因:

  • 百度推送配置出错
  • so文件只放在了工程lib下面,但没有被studio编译进apk

配置百度推送:

http://push.baidu.com/doc/android/api

让androidstudio编译so文件进apk

1.在app目录里面,编辑build.gradle,添加如下代码:

 android {
     ....

     task nativeLibsToJar(type: Zip, description: "create a jar archive of the native libs") {
         destinationDir file("$projectDir/libs")
         baseName "Native_Libs"
         extension "jar"
         from fileTree(dir: "libs", include: "**/*.so")
         into "lib"
     }

     tasks.withType(JavaCompile) {
         compileTask -> compileTask.dependsOn(nativeLibsToJar)
     }

     ...

 }

2.看到生成的 Native_Libs.jar后,往dependencies添加如下代码:

 dependencies {
     ...
     compile files('libs/Native_Libs.jar')
     ...

3.重新运行,OK,errorcode=0 ~

参考:http://blog.csdn.net/wulianghuan/article/details/44567001