谷歌云消息编码错误

时间:2016-04-06 18:26:40

标签: android

参考链接:http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/ 我已经使用了所有java文件和xml文件。

的AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.razin.kichuina"
        android:versionCode="1"
        android:versionName="1.0" >

        <!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
        <uses-sdk
            android:minSdkVersion="23"
            android:targetSdkVersion="23" />

        <!-- GCM connects to Internet Services. -->
        <uses-permission android:name="android.permission.INTERNET" />

        <!-- GCM requires a Google account. -->
        <uses-permission android:name="android.permission.GET_ACCOUNTS" />

        <!-- Keeps the processor from sleeping when a message is received. -->
        <uses-permission android:name="android.permission.WAKE_LOCK" />

        <!-- Creates a custom permission so only this app can receive its messages. -->
        <permission
            android:name="com.example.razin.kichuina.permission.C2D_MESSAGE"
            android:protectionLevel="signature" />

        <uses-permission android:name="com.example.razin.kichuina.permission.C2D_MESSAGE" />

        <!-- This app has permission to register and receive data message. -->
        <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

        <!-- Network State Permissions to detect Internet status -->
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

        <!-- Permission to vibrate -->
        <uses-permission android:name="android.permission.VIBRATE" />

        <!-- Main activity. -->
        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name" >
            <!-- Register Activity -->
            <activity
                android:name=".RegisterActivity"
                android:label="@string/app_name" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />

                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>

            <!-- Main Activity -->
            <activity
                android:name=".MainActivity"
                android:configChanges="orientation|keyboardHidden"
                android:label="@string/app_name" >
            </activity>

            <receiver
                android:name="com.google.android.gcm.GCMBroadcastReceiver"
                android:permission="com.google.android.c2dm.permission.SEND" >
                <intent-filter>

                    <!-- Receives the actual messages. -->
                    <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                    <!-- Receives the registration id. -->
                    <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                    <category android:name="com.example.razin.kichuina" />
                </intent-filter>
            </receiver>

            <service android:name=".GCMIntentService" />
        </application>

    </manifest>

的build.gradle

    apply plugin: 'com.android.application'
    android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    defaultConfig {
           applicationId "com.example.razin.kichuina"
           minSdkVersion 16
           targetSdkVersion 23
           versionCode 1
           versionName "1.0"
           // multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
   productFlavors {
           }
    }
    dependencies {
         compile fileTree(include: ['*.jar'], dir: 'libs')
         testCompile 'junit:junit:4.12'
          compile 'com.android.support:appcompat-v7:23.2.1'
         compile 'com.android.support:design:23.2.1'
        //  compile files('libs/android-support-v13.jar')
          compile files('libs/gcm.jar')
        // compile files('libs/android-support-vectordrawable.jar')
       //  compile files('libs/android-support-animatedvectordrawable.jar')
           compile files('libs/android-support-v4.jar')
     }

libs_contents

&#34; multiDexEnabled为true&#34>时出现

错误没有给出

    Information:Gradle tasks [:app:assembleDebug]
    :app:preBuild UP-TO-DATE
    :app:preDebugBuild UP-TO-DATE
    :app:checkDebugManifest
    :app:preReleaseBuild UP-TO-DATE
    :app:prepareComAndroidSupportAnimatedVectorDrawable2321Library UP-TO-DATE
    :app:prepareComAndroidSupportAppcompatV72321Library UP-TO-DATE
    :app:prepareComAndroidSupportDesign2321Library UP-TO-DATE
    :app:prepareComAndroidSupportRecyclerviewV72321Library UP-TO-DATE
    :app:prepareComAndroidSupportSupportV42321Library UP-TO-DATE
    :app:prepareComAndroidSupportSupportVectorDrawable2321Library UP-TO-DATE
    :app:prepareDebugDependencies
    :app:compileDebugAidl UP-TO-DATE
    :app:compileDebugRenderscript UP-TO-DATE
    :app:generateDebugBuildConfig UP-TO-DATE
    :app:generateDebugAssets UP-TO-DATE
    :app:mergeDebugAssets UP-TO-DATE
    :app:generateDebugResValues UP-TO-DATE
    :app:generateDebugResources UP-TO-DATE
    :app:mergeDebugResources
    AAPT err(Facade for 10027069): C:\Users\Razin\AndroidStudioProjects\kichuina\app\src\main\res\drawable\ic_action_search.png: libpng warning: iCCP: Not recognizing known sRGB profile that has been edited
    :app:processDebugManifest
    :app:processDebugResources
    :app:generateDebugSources
    :app:compileDebugJavaWithJavac
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    :app:compileDebugNdk UP-TO-DATE
    :app:compileDebugSources
    :app:transformClassesWithDexForDebug
    UNEXPECTED TOP-LEVEL EXCEPTION:
    Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
    > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_73\bin\java.exe'' finished with non-zero exit value 2
    BUILD FAILED
    Total time: 56.124 secs
    1 error
    0 warnings
    See complete output in console

Android监视器

                04-06 13:05:44.698 1307-1323/system_process E/BluetoothAdapter: Bluetooth binder is null
    04-06 13:05:44.965 1307-1323/system_process E/KernelCpuSpeedReader: Failed to read cpu-freq
                                                                        java.io.FileNotFoundException: /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state: open failed: ENOENT (No such file or directory)
                                                                            at libcore.io.IoBridge.open(IoBridge.java:452)
                                                                            at java.io.FileInputStream.<init>(FileInputStream.java:76)
                                                                            at java.io.FileInputStream.<init>(FileInputStream.java:103)
                                                                            at java.io.FileReader.<init>(FileReader.java:66)
                                                                            at com.android.internal.os.KernelCpuSpeedReader.readDelta(KernelCpuSpeedReader.java:49)
                                                                            at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8002)
                                                                            at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1366)
                                                                            at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:125)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:148)
                                                                            at android.os.HandlerThread.run(HandlerThread.java:61)
                                                                            at com.android.server.ServiceThread.run(ServiceThread.java:46)
                                                                         Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
                                                                            at libcore.io.Posix.open(Native Method)
                                                                            at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
                                                                            at libcore.io.IoBridge.open(IoBridge.java:438)
                                                                            at java.io.FileInputStream.<init>(FileInputStream.java:76) 
                                                                            at java.io.FileInputStream.<init>(FileInputStream.java:103) 
                                                                            at java.io.FileReader.<init>(FileReader.java:66) 
                                                                            at com.android.internal.os.KernelCpuSpeedReader.readDelta(KernelCpuSpeedReader.java:49) 
                                                                            at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8002) 
                                                                            at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1366) 
                                                                            at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:125) 
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                            at android.os.Looper.loop(Looper.java:148) 
                                                                            at android.os.HandlerThread.run(HandlerThread.java:61) 
                                                                            at com.android.server.ServiceThread.run(ServiceThread.java:46) 
    04-06 13:05:44.965 1307-1323/system_process E/KernelUidCpuTimeReader: Failed to read uid_cputime
                                                                          java.io.FileNotFoundException: /proc/uid_cputime/show_uid_stat: open failed: ENOENT (No such file or directory)
                                                                              at libcore.io.IoBridge.open(IoBridge.java:452)
                                                                              at java.io.FileInputStream.<init>(FileInputStream.java:76)
                                                                              at java.io.FileInputStream.<init>(FileInputStream.java:103)
                                                                              at java.io.FileReader.<init>(FileReader.java:66)
                                                                              at com.android.internal.os.KernelUidCpuTimeReader.readDelta(KernelUidCpuTimeReader.java:71)
                                                                              at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8031)
                                                                              at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1366)
                                                                              at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:125)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:148)
                                                                              at android.os.HandlerThread.run(HandlerThread.java:61)
                                                                              at com.android.server.ServiceThread.run(ServiceThread.java:46)
                                                                           Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
                                                                              at libcore.io.Posix.open(Native Method)
                                                                              at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
                                                                              at libcore.io.IoBridge.open(IoBridge.java:438)
                                                                              at java.io.FileInputStream.<init>(FileInputStream.java:76) 
                                                                              at java.io.FileInputStream.<init>(FileInputStream.java:103) 
                                                                              at java.io.FileReader.<init>(FileReader.java:66) 
                                                                              at com.android.internal.os.KernelUidCpuTimeReader.readDelta(KernelUidCpuTimeReader.java:71) 
                                                                              at com.android.internal.os.BatteryStatsImpl.updateCpuTimeLocked(BatteryStatsImpl.java:8031) 
                                                                              at com.android.server.am.BatteryStatsService.updateExternalStats(BatteryStatsService.java:1366) 
                                                                              at com.android.server.am.BatteryStatsService$BatteryStatsHandler.handleMessage(BatteryStatsService.java:125) 
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                              at android.os.Looper.loop(Looper.java:148) 
                                                                              at android.os.HandlerThread.run(HandlerThread.java:61) 
                                                                              at com.android.server.ServiceThread.run(ServiceThread.java:46) 
    04-06 13:05:45.352 1307-1317/system_process I/art: Background sticky concurrent mark sweep GC freed 15366(1329KB) AllocSpace objects, 6(120KB) LOS objects, 18% free, 7MB/8MB, paused 1.495ms total 379.099ms
    04-06 13:06:48.725 1307-1321/system_process I/ProcessStatsService: Prepared write state in 57ms
    04-06 13:06:48.726 1307-1321/system_process I/ProcessStatsService: Prepared write state in 1ms
    04-06 13:07:48.662 1307-1753/system_process I/ActivityManager: Killing 2050:com.android.managedprovisioning/u0a9 (adj 15): empty for 1806s
    04-06 13:08:02.239 2444-2451/com.example.razin.githubcode W/art: Suspending all threads took: 6.511ms
    04-06 13:08:48.717 1307-1319/system_process I/ActivityManager: Killing 2189:com.android.email/u0a28 (adj 13): empty for 1801s
    04-06 13:08:48.739 1307-1319/system_process I/ActivityManager: Killing 1709:android.process.media/u0a5 (adj 13): empty for 1809s
    04-06 13:08:48.756 1307-1319/system_process I/ActivityManager: Killing 2262:com.android.settings/1000 (adj 13): empty for 1810s
    04-06 13:08:48.776 1307-1319/system_process I/ActivityManager: Killing 2230:com.google.android.apps.messaging/u0a43 (adj 13): empty for 1810s
    04-06 13:08:48.796 1307-1319/system_process I/ActivityManager: Killing 1883:com.google.android.apps.maps/u0a37 (adj 13): empty for 1818s
    04-06 13:08:48.816 1307-1319/system_process I/ActivityManager: Killing 2204:com.android.exchange/u0a30 (adj 15): empty for 1818s
&#34; multiDexEnabled为true&#34>时出现

错误给定

    :app:transformClassesWithJarMergingForDebug FAILED
    Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
    > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/annotation/IntegerRes.class
    BUILD FAILED
    Total time: 2.024 secs
    1 error
    0 warnings
    See complete output in console

请告诉原因,请帮助我。我该怎么修改.plzzzz .......

2 个答案:

答案 0 :(得分:0)

在您的错误中,我猜您在导入此库时存在冲突

compile files('libs/gcm.jar')
compile files('libs/android-support-v4.jar')

并将这些行替换为此

compile "com.google.android.gms:play-services-gcm:8.4.0"
compile 'com.android.support:support-v4:23.2.1'

尝试在Android https://developers.google.com/cloud-messaging/android/client#add-config

上查看实施GCM的新方法

答案 1 :(得分:0)

查看此博客以供参考:

http://mobikul.com/android-gcm-push-notification/