iOS编译时报错The run destination John的 iPhone is not valid for Running the scheme 'Test'.

本文介绍了解决真机调试时出现的部署目标错误的方法。通过调整项目的部署目标为低于设备系统的版本,即可实现真机调试。适用于移动应用开发者。

有时候,我们在真机调试的时候回遇到这样的错误

通常,我们只需要这样操作就能解决问题

选择工程 -> General -> Deployment Info

将Deployment Target 修改至低于手机的系统版本就可以进行真机调试了

具体如下图所示:

如有其它编译上的错误可以咨询:

 

/**

 *  Author:Jn

 *  GitHubhttps://github.com/JnKindle

 *  cnblogshttp://www.cnblogs.com/JnKindle

 */

 

 

 

 

你遇到的错误: ``` 'com.example.bulbpage.whiteedit.EditAutoWhiteFragment' is not a valid destination for tag 'fragment' ``` 通常发生在 **使用 Navigation 组件进行 Fragment 跳转时,目标 Fragment 没有在导航图(`nav_graph.xml`)中正确定义**,或者你尝试跳转的方式不正确。 --- ## ✅ 错误原因分析 ### ❗原因 1:目标 Fragment 未在 `nav_graph.xml` 中定义 ```xml <fragment android:id="@+id/editAutoWhiteFragment" android:name="com.example.bulbpage.whiteedit.EditAutoWhiteFragment" android:label="EditAutoWhiteFragment" /> ``` 如果你没有在 `nav_graph.xml` 中声明这个 Fragment,调用 `navigate(R.id.editAutoWhiteFragment)` 时就会报错。 --- ### ❗原因 2:手动使用 `supportFragmentManager` 添加 Fragment 时使用了 `fragment` 标签 例如: ```kotlin supportFragmentManager.beginTransaction() .add(R.id.container, EditAutoWhiteFragment()) .addToBackStack(null) .commit() ``` 如果你使用的是 `NavController.navigate()`,但目标 Fragment 没在导航图中定义,也会报这个错。 --- ## ✅ 解决方案 ### ✅ 方法 1:确保 Fragment 在 `nav_graph.xml` 中定义 ```xml <navigation xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/nav_graph" app:startDestination="@id/mainFragment"> <fragment android:id="@+id/mainFragment" android:name="com.example.bulbpage.MainFragment" android:label="MainFragment" /> <fragment android:id="@+id/editAutoWhiteFragment" android:name="com.example.bulbpage.whiteedit.EditAutoWhiteFragment" android:label="EditAutoWhiteFragment" /> <!-- 可选:添加 action --> <action android:id="@+id/action_mainFragment_to_editAutoWhiteFragment" app:destination="@id/editAutoWhiteFragment" /> </navigation> ``` --- ### ✅ 方法 2:使用 NavController 进行跳转(推荐) ```kotlin val navController = findNavController() navController.navigate(R.id.editAutoWhiteFragment) ``` 确保你是在 Fragment 或 Activity 中使用 `findNavController()`,并且当前上下文属于 `NavHostFragment` 的视图层级。 --- ### ✅ 方法 3:使用 Safe Args(推荐,用于传参) 1. 在 `build.gradle` 中启用 Safe Args 插件: ```gradle plugins { id 'androidx.navigation.safeargs.kotlin' } ``` 2. 在 `nav_graph.xml` 中定义 action: ```xml <action android:id="@+id/action_mainFragment_to_editAutoWhiteFragment" app:destination="@id/editAutoWhiteFragment" /> ``` 3. 在代码中使用生成的类跳转: ```kotlin val action = MainFragmentDirections.actionMainFragmentToEditAutoWhiteFragment() findNavController().navigate(action) ``` --- ## ✅ 总结 | 问题 | 原因 | 解决方案 | |------|------|----------| | Fragment 不是有效的导航目标 | 未在 `nav_graph.xml` 中定义 | 在导航图中添加该 Fragment | | 跳转时报 tag fragment 错误 | 使用了非导航图方式添加 Fragment | 使用 `NavController.navigate()` 或检查跳转方式 | | Safe Args 未启用 | 无法使用类型安全跳转 | 启用插件并使用 `Directions` | ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值