admin管理员组文章数量:1356753
I’m encountering a persistent issue in Android Studio where BatteryStatsManager
and related classes (BatteryUsageStats
, BatteryUsageStatsQuery
, UidBatteryConsumer
) result in a Cannot resolve symbol
error, even though my project is configured with compileSdk = 35
(API 35, Android 15) and minSdk = 28
(API 28, Android 9.0), where BatteryStatsManager
was introduced.
Problem
Error: Android Studio flags BatteryStatsManager
with Cannot resolve symbol
at the import and usage lines.
Investigation: I checked \AppData\Local\Android\Sdk\platforms\android-35\android.jar
(and android-28\android.jar
) using 7-Zip:
android/os/ contains Bundle.class
, Build.class
, BatteryManager.class
, but not BatteryStatsManager.class
.
Expectation: Since BatteryStatsManager
is a public API (docs) introduced in API 28, it should be in android.jar for compileSdk >= 28
.
Steps Tried
Reinstalled SDK:
Uninstalled API 35 via Tools > SDK Manager > SDK Platforms
, reapplied, and repeated for API 28.
No change— BatteryStatsManager.class
still missing.
Full Reset:
Uninstalled Android Studio, deleted \AppData\Local\Android\Sdk
, reinstalled everything fresh.
Same result: android.jar
lacks BatteryStatsManager.class
.
Invalidated Caches:
File > Invalidate Caches / Restart
—fixed other import errors, but not this one.
Checked API 28:
Set compileSdk = 28
, installed API 28 SDK, checked android-28\android.jar
—still no BatteryStatsManager.class
.
Questions:
Why is BatteryStatsManager.class
not in android.jar?
It’s a public API, and other android.os
classes are present. Is this a bug in the SDK, or is it intentionally excluded from the compile-time stub?
Why the Cannot resolve symbol
error?
With compileSdk = 35
(or 28), Android Studio should recognize it if it’s in the SDK. Is my android.jar corrupted, or is BatteryStatsManager
handled differently?
How to fix this?
My app is a system app with BATTERY_STATS
permission, so I can use reflection (getSystemService("batterystats")
), but I’d prefer direct access for cleaner code and better IDE support.
本文标签:
版权声明:本文标题:Why is BatteryStatsManager.class Missing from android.jar and Causing "Cannot Resolve Symbol" Despite Correct 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743982113a2571126.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论