windows 7下 Rect-Native Android 环境下的配置

本文详细介绍了如何在Android环境下配置React Native开发环境,包括JDK、Android SDK的安装及环境变量配置,通过npm安装React-native-cli,以及创建并运行React Native项目的全过程。

Android环境配置

  1. JDK
    x86和x64都可以,我选则的是x86
    下载安装即可:
    这里写图片描述

    注意:配置环境变量:
    新建名称: 这里写图片描述
    path: PATH:

  2. 安装Android SDK(保证JDK安装完成)
    可以单独安装,也可以用android studio安装包,我安装在:D:/Android/sdk 目录下、

    注意:设置环境变量:
    新建:变量名:ANDROID_HOME 变量值:D:/Android/sdk
    path:%ANDROID_HOME%/tools;%ANDROID_HOME%/platform-tools

    安装React-native-cli

    镜像:国外网不能上的时候,加上这个
    npm config set registry https://registry.npm.taobao.org
    npm config set disturl https://npm.taobao.org/dist
    安装:
    npm install -g react-native-cli
    安装的目录:C:\Users\XXXX\AppData\Roaming\npm

    初始化项目

    在D盘新建一个目录(可以是其他盘)–reachnative,切换到D(新建的目录)盘
    cd reactnative
    react-native init reactNativeTest

    初始化的速度会根据网速来决定,一半几分钟到十几分钟

    切换目录

    cd reactNativeTest

    运行packager

    react-native start
    这样服务就开始运行了

    测试运行

    react-native run-android

效果

这里写图片描述

注:保证有真机或者模拟器(D:/Android/sdk/AVD Manager.exe)连接
如果报错
1、failed to find Build Tools revision 23.0.1
解决方案:在reactNativeTest/android/app/build.gradle文件中:
改为:buildToolsVersion “22.0.1” —- (22.0.1为已经安装的的版本)
或者:打开SDK Manager.exe,增加Build Tools revision 23.0.1
这里写图片描述

相关连接:
http://my.oschina.net/jackzlz/blog/508210
http://www.hacksparrow.com/react-native-android-failed-to-find-build-tools-revision-23-0-1.html
http://www.cnblogs.com/meteoric_cry/p/4874517.html

http://reactnative.cn/docs/0.31/getting-started.html

2025-09-06 02:51:39.535 11752-12832 ADB_SERVICES adbd I post waitpid (pid=12831) status=0000 2025-09-06 02:51:39.837 1095-2189 NtpTrustedTime system_server D currentTimeMillis() cache hit 2025-09-06 02:51:39.862 1095-2189 NetworkStatsRecorder system_server W unknown interfaces [wlan0, lo], ignoring those stats 2025-09-06 02:51:39.868 1095-2189 NtpTrustedTime system_server D currentTimeMillis() cache hit 2025-09-06 02:51:39.874 2487-3343 TrafficManageService com.miui.securitycenter.remote I mina mTrafficStatsReceiver onReceive 2025-09-06 02:51:39.875 1439-1832 PhoneInterfaceManager com.android.phone E [PhoneIntfMgr] checkCarrierPrivilegesForPackage: No UICC 2025-09-06 02:51:39.882 1439-1832 PhoneInterfaceManager com.android.phone E [PhoneIntfMgr] checkCarrierPrivilegesForPackage: No UICC 2025-09-06 02:51:39.883 626-626 ata_acm int....factoryInterface@1.0-service W type=1400 audit(0.0:21469): avc: denied { dac_override } for capability=1 scontext=u:r:factory_services:s0 tcontext=u:r:factory_services:s0 tclass=capability permissive=0 2025-09-06 02:51:39.892 626-712 factoryInterface_common int....factoryInterface@1.0-service E ERROR: factoryInterface,serial_config.cpp,265,open_usb(): Open /dev/ttyGS0 fail 2025-09-06 02:51:40.393 626-712 factoryInterface_common int....factoryInterface@1.0-service E ERROR: factoryInterface,serial_config.cpp,265,open_usb(): Open /dev/ttyGS0 fail 2025-09-06 02:51:40.383 626-626 ata_acm int....factoryInterface@1.0-service W type=1400 audit(0.0:21470): avc: denied { dac_override } for capability=1 scontext=u:r:factory_services:s0 tcontext=u:r:factory_services:s0 tclass=capability permissive=0 2025-09-06 02:51:40.679 1095-1191 PowerWrap system_server I PowerHal_TouchBoost 2025-09-06 02:51:40.699 1095-1191 PowerWrap system_server I PowerHal_TouchBoost 2025-09-06 02:51:40.883 626-626 ata_acm int....factoryInterface@1.0-service W type=1400 audit(0.0:21471): avc: denied { dac_override } for capability=1 scontext=u:r:factory_services:s0 tcontext=u:r:factory_services:s0 tclass=capability permissive=0 2025-09-06 02:51:40.894 626-712 factoryInterface_common int....factoryInterface@1.0-service E ERROR: factoryInterface,serial_config.cpp,265,open_usb(): Open /dev/ttyGS0 fail 2025-09-06 02:51:41.089 1095-1191 PowerWrap system_server I PowerHal_TouchBoost 2025-09-06 02:51:41.145 459-459 SurfaceFlinger surfaceflinger I [Built-in Screen (type:0)] fps:2.591705,dur:4244.31,max:3658.59,min:9.15 2025-09-06 02:51:41.182 1095-1191 PowerWrap system_server I PowerHal_TouchBoost 2025-09-06 02:51:41.218 12754-12754 AndroidRuntime person.tools.treasurebox D Shutting down VM 2025-09-06 02:51:41.227 12754-12754 AndroidRuntime person.tools.treasurebox E FATAL EXCEPTION: main Process: person.tools.treasurebox, PID: 12754 java.lang.NullPointerException: null cannot be cast to non-null type java.util.Calendar at person.tools.treasurebox.customview.widget.TrafficConsumptionLineChartMarker.refreshContent(TrafficConsumptionLineChartMarker.kt:55) at com.github.mikephil.charting.charts.Chart.drawMarkers(Chart.java:745) at com.github.mikephil.charting.charts.BarLineChartBase.onDraw(BarLineChartBase.java:271) at android.view.View.draw(View.java:20355) at android.view.View.updateDisplayListIfDirty(View.java:19195) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4381) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4354) at android.view.View.updateDisplayListIfDirty(View.java:19145) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4381) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4354) at android.view.View.updateDisplayListIfDirty(View.java:19145) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4381) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4354) at android.view.View.updateDisplayListIfDirty(View.java:19145) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4381) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4354) at android.view.View.updateDisplayListIfDirty(View.java:19145) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4381) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4354) at android.view.View.updateDisplayListIfDirty(View.java:19145) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4381) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4354) at android.view.View.updateDisplayListIfDirty(View.java:19145) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:686) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:692) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:801) at android.view.ViewRootImpl.draw(ViewRootImpl.java:3542) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3322) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2676) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1594) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7661) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1047) at android.view.Choreographer.doCallbacks(Choreographer.java:843) at android.view.Choreographer.doFrame(Choreographer.java:771) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1033) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:201) at android.app.ActivityThread.main(ActivityThread.java:6820) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:922) 2025-09-06 02:51:41.250 440-473 vendor.med...r@2.1-impl ven...ek.hardware.power@2.1-service I notifyAppState_2_1 pack:person.tools.treasurebox, act:person.tools.treasurebox, pid:12754, uid:10135, state:3 2025-09-06 02:51:41.251 2030-2053 octvm_klo mcd I klo lock 2025-09-06 02:51:39.863 1095-2189 chatty system_server I uid=1000(system) Binder:1095_B identical 2 lines 2025-09-06 02:51:39.864 1095-2189 NetworkStatsRecorder system_server W unknown interfaces [wlan0, lo], ignoring those stats 2025-09-06 02:51:41.252 1095-2189 ActivityManager system_server W Force finishing activity person.tools.treasurebox/.customview.view.LineChartMarkerActivity 2025-09-06 02:51:41.254 1095-2189 PowerWrap system_server I PowerHal_Wrap_mtkPowerHint 2025-09-06 02:51:41.255 1095-2189 PowerWrap system_server I PowerHal_Wrap_mtkPowerHint 2025-09-06 02:51:41.256 440-472 libPowerHal ven...ek.hardware.power@2.1-service I 17: cpu_ctrl set freq: 2001000 -1 1500000 -1 2025-09-06 02:51:41.263 1095-12833 AES system_server W Exception Log handling... 2025-09-06 02:51:41.263 1095-12833 AES system_server W Skipped - do not care third party apk 2025-09-06 02:51:41.264 12754-12754 Process person.tools.treasurebox I Sending signal. PID: 12754 SIG: 9 2025-09-06 02:51:41.265 1095-2189 ActivityManager system_server D report kill process: killerPid is:12754, killedPid is:12754 2025-09-06 02:51:41.269 2030-2053 octvm_klo mcd I get wanted event[mask:128, name:data_app_crash@1757098301263.txt] from the watchset ---------------------------- PROCESS ENDED (12754) for package person.tools.treasurebox ---------------------------- 2025-09-06 02:51:41.269 2030-2053 octvm_klo mcd I start gathering logcat log... 2025-09-06 02:51:41.283 1095-1190 InputDispatcher system_server W channel 'e2f25e9 person.tools.treasurebox/person.tools.treasurebox.customview.view.LineChartMarkerActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9 2025-09-06 02:51:41.283 1095-1190 InputDispatcher system_server E channel 'e2f25e9 person.tools.treasurebox/person.tools.treasurebox.customview.view.LineChartMarkerActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 2025-09-06 02:51:41.283 1095-1190 InputDispatcher system_server W channel '10e1762 person.tools.treasurebox/person.tools.treasurebox.customview.view.CustomViewTestActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x9 2025-09-06 02:51:41.284 1095-1190 InputDispatcher system_server E channel '10e1762 person.tools.treasurebox/person.tools.treasurebox.customview.view.CustomViewTestActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 2025-09-06 02:51:41.284 2030-2053 octvm_klo mcd I gathering logcat log done 2025-09-06 02:51:41.284 2030-2053 octvm_klo mcd I klo unlock 2025-09-06 02:51:41.284 11752-11752 ADB_SERVICES adbd I for fd 18, revents = 2011 2025-09-06 02:51:41.284 1095-8460 WindowManager system_server I WIN DEATH: Window{e2f25e9 u0 person.tools.treasurebox/person.tools.treasurebox.customview.view.LineChartMarkerActivity} 2025-09-06 02:51:41.284 11752-11752 ADB_SERVICES adbd I for fd 18, revents = 2011 2025-09-06 02:51:41.284 1095-8460 InputDispatcher system_server W Attempted to unregister already unregistered input channel 'e2f25e9 person.tools.treasurebox/person.tools.treasurebox.customview.view.LineChartMarkerActivity (server)' 2025-09-06 02:51:41.284 1095-2189 ActivityManager system_server I Process person.tools.treasurebox (pid 12754) has died: fore TOP 2025-09-06 02:51:41.284 1095-1114 libprocessgroup system_server W kill(-12754, 9) failed: No such process 2025-09-06 02:51:41.286 440-473 vendor.med...r@2.1-impl ven...ek.hardware.power@2.1-service I notifyAppState_2_1 pack:person.tools.treasurebox, act:person.tools.treasurebox, pid:12754, uid:10135, state:3 2025-09-06 02:51:41.288 1095-2818 WindowManager system_server I WIN DEATH: Window{10e1762 u0 person.tools.treasurebox/person.tools.treasurebox.customview.view.CustomViewTestActivity} 2025-09-06 02:51:41.288 1095-2818 InputDispatcher system_server W Attempted to unregister already unregistered input channel '10e1762 person.tools.treasurebox/person.tools.treasurebox.customview.view.CustomViewTestActivity (server)' 2025-09-06 02:51:41.290 1095-1114 libprocessgroup system_server W kill(-12754, 9) failed: No such process 2025-09-06 02:51:41.290 1095-1114 libprocessgroup system_server I Successfully killed process cgroup uid 10135 pid 12754 in 5ms 2025-09-06 02:51:41.297 459-1187 SurfaceFlinger surfaceflinger W Attempting to set client state on removed layer: person.tools.treasurebox/person.tools.treasurebox.customview.view.LineChartMarkerActivity#0 2025-09-06 02:51:41.297 459-1187 SurfaceFlinger surfaceflinger W Attempting to destroy on removed layer: person.tools.treasurebox/person.tools.treasurebox.customview.view.LineChartMarkerActivity#0 2025-09-06 02:51:41.299 1095-2189 PowerWrap system_server I PowerHal_Wrap_mtkPowerHint 2025-09-06 02:51:41.299 1095-2189 PowerWrap system_server I PowerHal_Wrap_mtkPowerHint 2025-09-06 02:51:41.300 1285-1285 EventBus com.android.systemui D [1285, u0] send(AppTransitionFinishedEvent) 2025-09-06 02:51:41.300 1285-1285 EventBus com.android.systemui D [1285, u0] -> ForcedResizableInfoActivityController [0x976a029, P1] onBusEvent(AppTransitionFinishedEvent) 2025-09-06 02:51:41.300 1285-1285 EventBus com.android.systemui D [1285, u0] onBusEvent(AppTransitionFinishedEvent) duration: 27 microseconds, avg: 862 2025-09-06 02:51:41.302 1095-2189 PowerWrap system_server I PowerHal_Wrap_mtkPowerHint 2025-09-06 02:51:41.302 1095-2189 PowerWrap system_server I PowerHal_Wrap_mtkPowerHint 2025-09-06 02:51:41.305 459-1187 SurfaceFlinger surfaceflinger I [SF client] Remove(0xaea97ee0) for (1095:system_server) 2025-09-06 02:51:41.309 454-2151 APM_AudioPolicyManager audioserver D AudioPolicyManager:setRecordSilenced(uid:10135, silenced:1) 2025-09-06 02:51:41.309 454-2151 AudioFlinger audioserver D AudioFlinger::setRecordSilenced(uid:10135, silenced:1) 2025-09-06 02:51:41.309 1095-1119 ActivityManager system_server W setHasOverlayUi called on unknown pid: 12754 2025-09-06 02:51:41.313 1095-1170 ViewRootIm...easurebox] system_server D hardware acceleration = false , fakeHwAccelerated = true, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false 2025-09-06 02:51:41.325 1095-1113 Boost system_server D hostingType=activity, hostingName=person.tools.treasurebox/.customview.view.CustomViewTestActivity, callerPackage=person.tools.treasurebox, isSystem=false, isBoostNeeded=false. 2025-09-06 02:51:41.326 607-634 thermal_repeater thermal I inotify_add_watch error! 2025-09-06 02:51:41.326 607-634 thermal_repeater thermal I Error 2: No such file or directory 2025-09-06 02:51:41.327 1095-1113 ActivityManager system_server I Start proc 12836:person.tools.treasurebox/u0a135 for activity person.tools.treasurebox/.customview.view.CustomViewTestActivity caller=person.tools.treasurebox 2025-09-06 02:51:41.335 12836-12836 ols.treasurebo pid-12836 I Late-enabling -Xcheck:jni 2025-09-06 02:51:41.341 612-638 ApmSession mtk_agpsd D Connect 2025-09-06 02:51:41.342 386-386 hwservicemanager hwservicemanager W getTransport: Cannot find entry vendor.mediatek.hardware.apmonitor@1.0::IAPMonitorService/default in either framework or device manifest. 2025-09-06 02:51:41.342 612-638 ApmSession mtk_agpsd D Connect: false 2025-09-06 02:51:41.342 612-638 ApmNative mtk_agpsd D apmIsKpiEnabled2: type = 54, ret = 0 2025-09-06 02:51:41.360 1095-1170 Surface system_server D lockCanvas 2025-09-06 02:51:41.360 1095-1170 Surface system_server D Surface::connect(this=0x90e39000,api=2) 2025-09-06 02:51:41.394 626-712 factoryInterface_common int....factoryInterface@1.0-service E ERROR: factoryInterface,serial_config.cpp,265,open_usb(): Open /dev/ttyGS0 fail 2025-09-06 02:51:41.383 626-626 ata_acm int....factoryInterface@1.0-service W type=1400 audit(0.0:21472): avc: denied { dac_override } for capability=1 scontext=u:r:factory_services:s0 tcontext=u:r:factory_services:s0 tclass=capability permissive=0 2025-09-06 02:51:41.396 11752-11752 ADB_SERVICES adbd I local_socket_flush_incoming write_data=1250735 2025-09-06 02:51:41.400 11752-11752 ADB_SERVICES adbd I service_to_fd shell:stat -c %u /proc/12836 | xargs -n 1 cmd package list packages --uid 2025-09-06 02:51:41.403 12836-12836 re-initialized> pid-12836 W type=1400 audit(0.0:21473): avc: denied { read } for name="u:object_r:mtk_amslog_prop:s0" dev="tmpfs" ino=9762 scontext=u:r:untrusted_app:s0:c135,c256,c512,c768 tcontext=u:object_r:mtk_amslog_prop:s0 tclass=file permissive=0 2025-09-06 02:51:41.410 12836-12836 libc pid-12836 E Access denied finding property "persist.vendor.sys.activitylog" 2025-09-06 02:51:41.423 440-473 vendor.med...r@2.1-impl ven...ek.hardware.power@2.1-service I notifyAppState_2_1 pack:person.tools.treasurebox, act:person.tools.treasurebox.customview.view.CustomViewTestActivity, pid:12836, uid:10135, state:1 2025-09-06 02:51:41.424 1285-1285 EventBus com.android.systemui D [1285, u0] send(AppTransitionFinishedEvent) 2025-09-06 02:51:41.425 1095-1170 Timeline system_server I Timeline: App_transition_ready time:9127560 2025-09-06 02:51:41.425 1285-1285 EventBus com.android.systemui D [1285, u0] -> ForcedResizableInfoActivityController [0x976a029, P1] onBusEvent(AppTransitionFinishedEvent) 2025-09-06 02:51:41.425 1285-1285 EventBus com.android.systemui D [1285, u0] onBusEvent(AppTransitionFinishedEvent) duration: 20 microseconds, avg: 860 2025-09-06 02:51:41.425 1095-1170 Timeline system_server I Timeline: App_transition_stopped time:9127560 2025-09-06 02:51:41.427 1285-1285 EventBus com.android.systemui D [1285, u0] send(AppTransitionFinishedEvent) 2025-09-06 02:51:41.428 1285-1285 EventBus com.android.systemui D [1285, u0] -> ForcedResizableInfoActivityController [0x976a029, P1] onBusEvent(AppTransitionFinishedEvent) 2025-09-06 02:51:41.428 1285-1285 EventBus com.android.systemui D [1285, u0] onBusEvent(AppTransitionFinishedEvent) duration: 30 microseconds, avg: 857 2025-09-06 02:51:41.428 454-8468 APM_AudioPolicyManager audioserver D AudioPolicyManager:setRecordSilenced(uid:10135, silenced:0) ---------------------------- PROCESS STARTED (12836) for package person.tools.treasurebox ---------------------------- 2025-09-06 02:51:41.428 454-8468 AudioFlinger audioserver D AudioFlinger::setRecordSilenced(uid:10135, silenced:0) 2025-09-06 02:51:41.533 11752-11752 ADB_SERVICES adbd I for fd 29, revents = 10 2025-09-06 02:51:41.534 11752-12850 ADB_SERVICES adbd I post waitpid (pid=12848) status=0000 2025-09-06 02:51:41.671 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden field Landroid/os/Trace;->TRACE_TAG_APP:J (light greylist, reflection) 2025-09-06 02:51:41.672 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/os/Trace;->isTagEnabled(J)Z (light greylist, reflection) 2025-09-06 02:51:41.722 12836-12836 AppCompatDelegate person.tools.treasurebox D Checking for metadata for AppLocalesMetadataHolderService : Service not found 2025-09-06 02:51:41.783 12836-12836 Binder:intercep person.tools.treasurebox W type=1400 audit(0.0:21474): avc: denied { getattr } for path="/data/data/com.miui.contentcatcher" dev="dm-2" ino=3088579 scontext=u:r:untrusted_app:s0:c135,c256,c512,c768 tcontext=u:object_r:system_app_data_file:s0 tclass=dir permissive=0 2025-09-06 02:51:41.794 12836-12861 ViewContentFactory person.tools.treasurebox D initViewContentFetcherClass 2025-09-06 02:51:41.794 12836-12861 ViewContentFactory person.tools.treasurebox D getInterceptorPackageInfo 2025-09-06 02:51:41.794 12836-12861 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/app/AppGlobals;->getInitialApplication()Landroid/app/Application; (light greylist, linking) 2025-09-06 02:51:41.795 12836-12861 ViewContentFactory person.tools.treasurebox D getInitialApplication took 2ms 2025-09-06 02:51:41.796 12836-12861 ViewContentFactory person.tools.treasurebox D packageInfo.packageName: com.miui.catcherpatch 2025-09-06 02:51:41.803 12836-12836 Binder:intercep person.tools.treasurebox W type=1400 audit(0.0:21475): avc: denied { getattr } for path="/data/data/com.miui.catcherpatch" dev="dm-2" ino=3114656 scontext=u:r:untrusted_app:s0:c135,c256,c512,c768 tcontext=u:object_r:system_app_data_file:s0 tclass=dir permissive=0 2025-09-06 02:51:41.814 12836-12861 ViewContentFactory person.tools.treasurebox D initViewContentFetcherClass took 21ms 2025-09-06 02:51:41.815 12836-12861 ContentCatcher person.tools.treasurebox I ViewContentFetcher : ViewContentFetcher 2025-09-06 02:51:41.815 12836-12861 ViewContentFactory person.tools.treasurebox D createInterceptor took 21ms 2025-09-06 02:51:41.822 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection) 2025-09-06 02:51:41.895 626-712 factoryInterface_common int....factoryInterface@1.0-service E ERROR: factoryInterface,serial_config.cpp,265,open_usb(): Open /dev/ttyGS0 fail 2025-09-06 02:51:41.893 626-626 ata_acm int....factoryInterface@1.0-service W type=1400 audit(0.0:21476): avc: denied { dac_override } for capability=1 scontext=u:r:factory_services:s0 tcontext=u:r:factory_services:s0 tclass=capability permissive=0 2025-09-06 02:51:41.898 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/graphics/FontFamily;-><init>()V (light greylist, reflection) 2025-09-06 02:51:41.898 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/graphics/FontFamily;->addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontVariationAxis;)Z (light greylist, reflection) 2025-09-06 02:51:41.898 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/graphics/FontFamily;->addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontVariationAxis;II)Z (light greylist, reflection) 2025-09-06 02:51:41.898 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/graphics/FontFamily;->freeze()Z (light greylist, reflection) 2025-09-06 02:51:41.898 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/graphics/FontFamily;->abortCreation()V (light greylist, reflection) 2025-09-06 02:51:41.899 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/graphics/Typeface;->createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (light greylist, reflection) 2025-09-06 02:51:41.994 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection) 2025-09-06 02:51:42.053 12836-12836 SurfaceFactory person.tools.treasurebox I [static] sSurfaceFactory = com.mediatek.view.impl.SurfaceFactoryImpl@35df084 2025-09-06 02:51:42.069 12836-12836 ViewRootIm...tActivity] person.tools.treasurebox D hardware acceleration = true , fakeHwAccelerated = false, sRendererDisabled = false, forceHwAccelerated = false, sSystemRendererDisabled = false 2025-09-06 02:51:42.072 459-1187 SurfaceFlinger surfaceflinger I [SF client] NEW(0xab9552d0) for (1095:system_server) 2025-09-06 02:51:42.077 12836-12836 PhoneWindow person.tools.treasurebox V DecorView setVisiblity: visibility = 0, Parent = android.view.ViewRootImpl@5842533, this = DecorView@50b90f0[CustomViewTestActivity] 2025-09-06 02:51:42.079 1095-1196 UiModeManager system_server V switch night mode to 1 2025-09-06 02:51:42.085 607-607 thermal_repeater thermal I [recvMdThermalInfo] ret=30, strLen=127, 3, 39, -127, 0, 32767, -28377 2025-09-06 02:51:42.136 1095-1267 WindowManager system_server I Relayout Window{479f0cd u0 person.tools.treasurebox/person.tools.treasurebox.customview.view.CustomViewTestActivity}: oldVis=4 newVis=0 focusMayChange = true 2025-09-06 02:51:42.150 12836-12836 Surface person.tools.treasurebox D Surface::allocateBuffers(this=0xa47ad000) 2025-09-06 02:51:42.159 459-459 SurfaceFlinger surfaceflinger I [Built-in Screen (type:0)] fps:12.829244,dur:1013.31,max:649.58,min:13.13 2025-09-06 02:51:42.159 12836-12862 ConfigStore person.tools.treasurebox I android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0 2025-09-06 02:51:42.159 12836-12862 ConfigStore person.tools.treasurebox I android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0 2025-09-06 02:51:42.159 12836-12862 OpenGLRenderer person.tools.treasurebox I Initialized EGL, version 1.4 2025-09-06 02:51:42.159 12836-12862 OpenGLRenderer person.tools.treasurebox D Swap behavior 2 2025-09-06 02:51:42.168 12836-12836 Looper person.tools.treasurebox W Slow Looper main: doFrame is 390ms late because of 3 msg, msg 1 took 391ms (late=59ms h=android.app.ActivityThread$H w=159) 2025-09-06 02:51:42.180 12836-12862 Surface person.tools.treasurebox D Surface::connect(this=0xa47ad000,api=1) 2025-09-06 02:51:42.183 12836-12862 libEGL person.tools.treasurebox I [MTK Game SDK] low_latency_mode(0) pid(-1) property(-1) 2025-09-06 02:51:42.248 12836-12862 ion person.tools.treasurebox E ioctl c0044901 failed with code -1: Invalid argument 2025-09-06 02:51:42.292 1095-1170 View system_server D [Warning] assignParent to null: this = DecorView@752c93[treasurebox] 2025-09-06 02:51:42.292 1095-1119 ActivityManager system_server I Displayed person.tools.treasurebox/.customview.view.CustomViewTestActivity: +986ms 2025-09-06 02:51:42.293 1095-1119 Timeline system_server I Timeline: Activity_windows_visible id: ActivityRecord{d4d52dd u0 person.tools.treasurebox/.customview.view.CustomViewTestActivity t55} time:9128428 2025-09-06 02:51:42.310 1095-1170 Surface system_server D Surface::disconnect(this=0x90e39000,api=2) 2025-09-06 02:51:42.311 459-495 SurfaceFlinger surfaceflinger W Attempting to set client state on removed layer: Splash Screen person.tools.treasurebox#0 2025-09-06 02:51:42.311 459-495 SurfaceFlinger surfaceflinger W Attempting to destroy on removed layer: Splash Screen person.tools.treasurebox#0 2025-09-06 02:51:42.315 1095-1267 PowerWrap system_server I PowerHal_Wrap_mtkPowerHint 2025-09-06 02:51:42.315 1095-1267 PowerWrap system_server I PowerHal_Wrap_querySysInfo 2025-09-06 02:51:42.317 1095-1267 PowerHalWrapper system_server E <amsBoostStop> duration: 6000ms 2025-09-06 02:51:42.317 1095-1267 PowerWrap system_server I PowerHal_Wrap_mtkPowerHint 2025-09-06 02:51:42.317 1095-1267 PowerWrap system_server I PowerHal_Wrap_mtkPowerHint 2025-09-06 02:51:42.395 626-712 factoryInterface_common int....factoryInterface@1.0-service E ERROR: factoryInterface,serial_config.cpp,265,open_usb(): Open /dev/ttyGS0 fail 2025-09-06 02:51:42.393 626-626 ata_acm int....factoryInterface@1.0-service W type=1400 audit(0.0:21477): avc: denied { dac_override } for capability=1 scontext=u:r:factory_services:s0 tcontext=u:r:factory_services:s0 tclass=capability permissive=0 2025-09-06 02:51:42.547 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/os/Trace;->asyncTraceBegin(JLjava/lang/String;I)V (light greylist, reflection) 2025-09-06 02:51:42.547 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/os/Trace;->asyncTraceEnd(JLjava/lang/String;I)V (light greylist, reflection) 2025-09-06 02:51:42.548 12836-12836 ols.treasurebo person.tools.treasurebox W Accessing hidden method Landroid/os/Trace;->traceCounter(JLjava/lang/String;I)V (light greylist, reflection) 2025-09-06 02:51:42.895 626-712 factoryInterface_common int....factoryInterface@1.0-service E ERROR: factoryInterface,serial_config.cpp,265,open_usb(): Open /dev/ttyGS0 fail 2025-09-06 02:51:42.893 626-626 ata_acm int....factoryInterface@1.0-service W type=1400 audit(0.0:21478): avc: denied { dac_override } for capability=1 scontext=u:r:factory_services:s0 tcontext=u:r:factory_services:s0 tclass=capability permissive=0 崩溃分析
09-07
<think>好的,用户发来了一大段Android的logcat日志,需要进行崩溃分析。首先,我需要仔细阅读这些日志,找出关键的错误信息。 在日志中,我看到有一个FATAL EXCEPTION发生在person.tools.treasurebox这个应用的TrafficConsumptionLineChartMarker的refreshContent方法中,错误是java.lang.NullPointerException: null cannot be cast to non-null type java.util.Calendar。这说明在某个地方尝试将null值转换为非空的Calendar类型,导致崩溃。 接下来,我需要定位到具体的代码位置。根据错误堆栈,问题出在TrafficConsumptionLineChartMarker.kt的第55行。用户可能需要检查这行代码,看看是否有变量未正确初始化或者可能为null的情况。 另外,日志中还有一些其他的信息,比如多次出现的Open /dev/ttyGS0 fail,这可能与设备的USB连接或硬件相关问题有关,但可能不是导致崩溃的主因。不过用户可能也需要关注这个问题,如果应用依赖于这个设备文件的话。 还有,应用在崩溃后被系统强制结束,然后重新启动了CustomViewTestActivity。用户可能需要检查Activity的启动流程和状态保存,确保在异常处理时不会导致数据丢失或状态不一致。 可能用户需要了解如何避免类似的NullPointerException,比如使用安全的类型转换,或者在访问可能为null的对象前进行检查。此外,日志中的其他警告,如访问隐藏API或权限问题,也可能需要检查,但当前崩溃的主因是类型转换错误。 总结下来,用户的问题主要是由于类型转换错误导致的崩溃,需要检查相关代码的空值处理。同时,可能还需要考虑其他潜在的问题,比如USB设备访问失败和权限配置等。</think>根据日志分析,应用崩溃的核心原因是**类型转换异常**,具体定位如下: 1. **崩溃位置** ``` java.lang.NullPointerException: null cannot be cast to non-null type java.util.Calendar at person.tools.treasurebox.customview.widget.TrafficConsumptionLineChartMarker.refreshContent(TrafficConsumptionLineChartMarker.kt:55) ``` - **问题代码**:`TrafficConsumptionLineChartMarker.kt` 第55行尝试将 `null` 值强制转换为 `java.util.Calendar` 类型。 - **直接原因**:某个对象为 `null`,但代码未进行空值检查,直接进行了非空类型转换。 2. **修复建议** - 在类型转换前添加空值检查: ```kotlin val obj: Any? = ... // 获取的对象 if (obj is Calendar) { // 安全使用 obj 作为 Calendar } else { // 处理 obj 为 null 或非 Calendar 的情况 } ``` - 使用安全转换操作符 `as?`: ```kotlin val calendar = obj as? Calendar calendar?.let { // 使用 it 作为 Calendar } ?: run { // 处理 null 情况 } ``` 3. **其他潜在问题** - **USB设备访问失败**:日志中多次出现 `open_usb(): Open /dev/ttyGS0 fail`,需检查设备权限或硬件连接。 - **权限警告**:`avc: denied { dac_override }` 表明应用可能需要调整 SELinux 权限配置- **隐藏API访问**:如 `android/os/Trace` 等隐藏方法的访问可能导致兼容性问题,建议使用公开API。 --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值