【问题标题】:Could not find method android.app.Notification$Builder.setLocalOnly找不到方法 android.app.Notification$Builder.setLocalOnly
【发布时间】:2016-03-04 11:13:50
【问题描述】:

我的应用有以下参数:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "de.munich.myApp"
        minSdkVersion 17
        targetSdkVersion 23
        multiDexEnabled true
    }

    buildTypes {
        debug {
            debuggable true
        }
        release {
            minifyEnabled false
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

我包含了支持包 v7:

dependencies {
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.android.support:design:23.2.0'
    compile 'com.android.support:recyclerview-v7:23.2.0'
    compile 'com.android.support:cardview-v7:23.2.0'
}

现在我尝试在具有 Android 版本 4.4.2(API 级别 19)的 Galaxy Ace 上启动我的应用程序,但由于找不到 android.support.v7 引用的某些方法,我收到了很多错误:

Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onSearchRequested
Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.internal.view.WindowCallbackWrapper.onWindowStartingActionMode
Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType

应用程序当然会崩溃。

我有什么方法可以解决这些问题而不必增加minSdkVersion

编辑

import android.app.Notification;
import android.content.Context;
import android.support.v4.app.NotificationCompat;

public class HelperNotification {

    /**
     *
     * @param context
     * @param title
     * @param message
     * @return
     */
    public static NotificationCompat.Builder buildNotification(Context context, String title, String message) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

        builder.setContentTitle(title);
        builder.setContentText(message);

        int defaults = 0;
        defaults = defaults | Notification.DEFAULT_LIGHTS;
        defaults = defaults | Notification.DEFAULT_VIBRATE;
        defaults = defaults | Notification.DEFAULT_SOUND;

        builder.setDefaults(defaults);

        return builder;
    }
}

编辑 2

I/dalvikvm: Could not find method android.os.UserManager.getApplicationRestrictions, referenced from method com.google.android.gms.common.zze.zzaq
W/dalvikvm: VFY: unable to resolve virtual method 1747: Landroid/os/UserManager;.getApplicationRestrictions (Ljava/lang/String;)Landroid/os/Bundle;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x0012
E/dalvikvm: Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.zze.zzb
W/dalvikvm: VFY: unable to resolve check-cast 35 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/zze;
D/dalvikvm: VFY: replacing opcode 0x1f at 0x000e
I/dalvikvm: Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.zze.zzi
W/dalvikvm: VFY: unable to resolve virtual method 605: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;
D/dalvikvm: VFY: replacing opcode 0x6e at 0x000b
I/GMPM: App measurement is starting up, version: 8487
I/GMPM: To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE
E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services.  Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
E/GMPM: Scheduler not set. Not logging error/warn.
E/GMPM: Uploading is not possible. App measurement disabled
D/dalvikvm: GC_CONCURRENT freed 265K, 16% free 8722K/10356K, paused 5ms+2ms, total 26ms
W/dalvikvm: VFY: unable to find class referenced in signature (Lde/hof/my_project/enums/status/images/StatusImageScale;)
W/dalvikvm: VFY: unable to resolve static field 34720 ($SwitchMap$de$hof$my_project$enums$status$images$StatusImageScale) in Lde/hof/my_project/fragments/FragmentSplash$1;
D/dalvikvm: VFY: replacing opcode 0x62 at 0x0000
E/dalvikvm: Could not find class 'de.hof.my_project.tasks.images.TaskImagesScale', referenced from method de.hof.my_project.fragments.FragmentSplash.onViewCreated
W/dalvikvm: VFY: unable to resolve new-instance 9154 (Lde/hof/my_project/tasks/images/TaskImagesScale;) in Lde/hof/my_project/fragments/FragmentSplash;
D/dalvikvm: VFY: replacing opcode 0x22 at 0x0003
D/dalvikvm: DexOpt: unable to opt direct call 0xf89d at 0x05 in Lde/hof/my_project/fragments/FragmentSplash;.onViewCreated

我添加了一些铁道部日志输出。这是当我在带有 API 17(我的最低要求 API)的三星 Galaxy S3 上运行我的应用程序时。上周,在我将库从 23.0 更新到 23.2 之前,一切正常。现在好像他找不到我定义的一些类。

【问题讨论】:

  • 您使用自定义主题吗?项目中除了activity/layout/build.gradle还有什么?

标签: android


【解决方案1】:

要回答问题标题上的问题,您应该将Notification更改为NotificationCompat,即:

NotificationCompat.Builder.

常规 Notification.Builder 具有 setLocal 仅在 API 20 之后可用。

【讨论】:

  • 您好,谢谢您的回答。我编辑了我的帖子,向您展示我是如何创建通知的。如您所见,我已经在使用NotificationCompat
【解决方案2】:

我找到了解决办法。

问题与65K Methods Count 有关。 我做了链接中推荐的android,所以我 能够在较旧的设备上再次安装该应用程序 API。

【讨论】:

  • 这真的是多索引问题吗?
  • 看来是这样。在我为旧版本添加了 multidex 支持所需的一切之后,它又可以正常工作了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
  • 2011-10-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-07
  • 2020-03-16
  • 2021-05-31
相关资源
最近更新 更多