找不到android.app.ApplicationPackageManager

时间:2017-06-10 12:19:38

标签: android robolectric android-package-managers

robolectric migration guide

编译以下示例时
package com.jongla.soundmash.robolectric
import org.robolectric.shadows.ShadowApplicationPackageManager
import org.robolectric.annotation.Implements
import android.app.ApplicationPackageManager

@Implements(value = ApplicationPackageManager.class, inheritImplementationMethods = true)
class MyCustomPackageManager extends ShadowApplicationPackageManager {
}

AndroidStudio正在给我Unresolved reference: ApplicationPackageManager。有谁知道我需要做什么才能让这个例子编译?我是否需要在gradle中添加一些额外的testCompile包?

1 个答案:

答案 0 :(得分:0)

在浏览Roboloectric源代码时,我发现了属性className来指定类名。它就像魔术一样。

@Implements(className = "android.app.ApplicationPackageManager", inheritImplementationMethods = true)
public class MyCustomPackageManager extends ShadowApplicationPackageManager {
}

当建议将值用作ApplicationPackageManager类是私有的并且对于用户代码不可见时,迁移文档显然是不正确的。