colcon build [1.040s] ERROR:colcon:colcon build: Duplicate package names not supported: - learning_pkg_python: - src/learning_pkg_python - src/ros2_21_tutorials/learning_pkg_python wheeltec@galactic:~/dev_ws1$
时间: 2025-07-23 17:09:43 浏览: 27
<think>我们正在解决ROS2中使用colcon build时出现的重复包名错误。错误信息为“Duplicate package names not supported”。根据用户提供的信息,错误涉及到的包名为“learning_pkg_python”。
在ROS2中,每个包必须具有唯一的名称。如果两个或多个包具有相同的名称,colcon在构建时就会报错。因此,我们需要确保工作空间中所有包的名称都是唯一的。
解决步骤:
1. 定位问题:首先,我们需要找出工作空间中所有名为“learning_pkg_python”的包。可能有多个包使用了相同的名称,或者同一个包被多次包含(例如,通过符号链接或复制)。
2. 修改包名:对于重复的包,我们需要修改其中一个包的名称,使其唯一。修改包名需要更改两个地方:
a. 在包的`package.xml`文件中,修改`<name>learning_pkg_python</name>`为新的唯一名称。
b. 在包的`setup.py`(对于Python包)或`CMakeLists.txt`(对于C++包)中,修改`package_name`或`project()`对应的名称,使其与`package.xml`中的新名称一致。
3. 清理构建:在修改包名后,建议清理构建目录和安装目录,然后重新构建,以避免旧缓存的影响。
另外,根据引用[1]中的提示,我们也可以使用`COLCON_IGNORE`文件来忽略某些包,但这不是解决重复包名的根本方法,因为我们需要的是所有包都参与构建但名称唯一。
根据引用[2],环境变量的设置也很重要,但重复包名错误与环境变量无关。
因此,我们专注于修改包名。
具体操作:
步骤1:查找重复的包
在终端中,进入工作空间根目录,运行以下命令来查找所有名为“learning_pkg_python”的包:
```bash
find src -name package.xml | xargs grep -l "<name>learning_pkg_python</name>"
```
这个命令会在`src`目录下查找所有包含`<name>learning_pkg_python</name>`的`package.xml`文件,并输出文件路径。这样我们就可以知道哪些包使用了相同的名称。
步骤2:修改包名
对于每一个重复的包(除了保留一个之外),我们需要修改包名。例如,我们可以将其中一个包改为`learning_pkg_python2`或其他名称。
修改示例(以Python包为例):
在重复的包中,打开`package.xml`,将:
```xml
<name>learning_pkg_python</name>
```
修改为:
```xml
<name>learning_pkg_python2</name>
```
然后,在同一个包中,打开`setup.py`(如果存在),找到`setup`函数中的`name`参数,修改为相同的名称:
```python
setup(
name='learning_pkg_python2',
...
)
```
步骤3:清理并重新构建
删除构建、安装和日志目录(如果存在):
```bash
rm -rf build install log
```
或者使用colcon的清理命令(如果colcon版本支持):
```bash
colcon build --cmake-clean-first
```
但更彻底的清理是手动删除这些目录。
然后重新构建:
```bash
colcon build
```
注意事项:
- 如果修改包名后,代码中引用了原包名(例如在Python中导入模块),则需要相应地修改导入语句,使用新的包名。
- 确保修改后的包名符合ROS2的命名规范(通常是小写字母、数字和下划线,且不以数字开头)。
通过以上步骤,应该可以解决重复包名的问题。
如果问题仍然存在,请检查是否有其他包使用了相同的名称,或者是否有旧版本的工作空间干扰(例如环境变量指向了其他工作空间)。
相关问题:
1. 如何避免ROS2包命名冲突?
2. 除了修改包名,还有哪些方法可以处理重复包名错误?
3. 在ROS2中,包名与节点名、话题名等命名空间有何区别?</think>### 解决ROS2 colcon build重复包名错误
当出现`Duplicate package names not supported`错误时,表明工作空间中存在多个同名的ROS包。以下是系统化的解决步骤:
#### 1. **定位重复包**
```bash
# 在工作空间根目录执行
find src -name package.xml | xargs grep "<name>learning_pkg_python</name>"
```
此命令会列出所有包含`<name>learning_pkg_python</name>`的`package.xml`文件路径,确认重复包的位置[^1]。
#### 2. **解决方案**
**方案A:重命名其中一个包**
1. 修改`package.xml`:
```xml
<!-- 原内容 -->
<name>learning_pkg_python</name>
<!-- 修改为 -->
<name>learning_pkg_python_v2</name> <!-- 确保唯一性 -->
```
2. 同步修改构建文件:
- **Python包**:更新`setup.py`中的`name`参数
- **CMake包**:更新`CMakeLists.txt`中的`project()`名称
3. 更新代码中所有对旧包名的引用(如Python的`import`语句)
**方案B:忽略重复包**
```bash
# 在不需要的包目录中创建空文件
touch src/unwanted_pkg/COLCON_IGNORE
```
这会使colcon跳过该包的构建[^1]。
#### 3. **清理与验证**
```bash
# 彻底清理构建缓存
rm -rf build install log
# 重新构建(添加详细输出)
colcon build --symlink-install --event-handlers console_direct+
```
观察输出中是否还有`learning_pkg_python`的重复报告。
#### 4. **环境检查**
检查环境变量是否冲突:
```bash
echo $ROS_PACKAGE_PATH
```
如果包含多个工作空间路径,临时重置:
```bash
unset ROS_PACKAGE_PATH
source /opt/ros/humble/setup.zsh # 根据ROS版本调整
```
### 关键注意事项
1. **唯一性规则**:ROS2要求工作空间内所有包的`package.xml`名称必须唯一
2. **隐藏文件**:检查是否有隐藏的副本(如`src/.backup/learning_pkg_python`)
3. **符号链接**:避免使用`ln -s`链接包,可能被colcon视为重复实体
> **故障树**:若问题持续,按顺序检查:
> 1. 工作空间结构是否包含嵌套`src`目录
> 2. `colcon.pkg`元数据文件是否残留旧信息
> 3. 是否误安装了同名系统包(`apt list --installed | grep learning_pkg`)
阅读全文
相关推荐

















Executing tasks: [:app:assembleDebug] in project D:\TestProject\MyApplication > Task :app:createDebugVariantModel UP-TO-DATE > Task :app:preBuild UP-TO-DATE > Task :app:preDebugBuild UP-TO-DATE > Task :app:mergeDebugNativeDebugMetadata NO-SOURCE > Task :app:compileDebugAidl NO-SOURCE > Task :app:compileDebugRenderscript NO-SOURCE > Task :app:generateDebugBuildConfig UP-TO-DATE > Task :app:javaPreCompileDebug UP-TO-DATE > Task :app:checkDebugAarMetadata UP-TO-DATE AGPBI: {"kind":"warning","text":"Your project has set android.useAndroidX=true, but configuration :app:debugRuntimeClasspath still contains legacy support libraries, which may cause runtime issues.\nThis behavior will not be allowed in Android Gradle plugin 8.0.\nPlease use only AndroidX dependencies or set android.enableJetifier=true in the gradle.properties file to migrate your project to AndroidX (see https://developer.android.com/jetpack/androidx/migrate for more info).\nThe following legacy support libraries are detected:\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0 -> com.android.support:support-annotations:28.0.0\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0 -> com.android.support:collections:28.0.0\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0 -> android.arch.lifecycle:runtime:1.1.1\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0 -> android.arch.lifecycle:runtime:1.1.1 -> android.arch.lifecycle:common:1.1.1\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0 -> android.arch.lifecycle:runtime:1.1.1 -> android.arch.core:common:1.1.1\n:app:debugRuntimeClasspath -> com.android.support:support-compat:28.0.0 -> com.android.support:versionedparcelable:28.0.0","sources":[{}]} > Task :app:generateDebugResValues UP-TO-DATE > Task :app:mapDebugSourceSetPaths UP-TO-DATE > Task :app:generateDebugResources UP-TO-DATE > Task :app:mergeDebugResources UP-TO-DATE > Task :app:packageDebugResources UP-TO-DATE > Task :app:parseDebugLocalResources UP-TO-DATE > Task :app:createDebugCompatibleScreenManifests UP-TO-DATE > Task :app:extractDeepLinksDebug UP-TO-DATE > Task :app:processDebugMainManifest FAILED [androidx.versionedparcelable:versionedparcelable:1.1.1] C:\Users\wangsen\.gradle\caches\transforms-3\4b621581b14be943fef7e9025808a5ef\transformed\versionedparcelable-1.1.1\AndroidManifest.xml Warning: Namespace 'androidx.versionedparcelable' used in: androidx.versionedparcelable:versionedparcelable:1.1.1, com.android.support:versionedparcelable:28.0.0. D:\TestProject\MyApplication\app\src\main\AndroidManifest.xml:22:18-91 Error: Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.7.0] AndroidManifest.xml:24:18-86 value=(androidx.core.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:7:5-25:19 to override. See https://developer.android.com/r/studio-ui/build/manifest-merger for more information about the manifest merger. > Task :app:mergeDebugShaders UP-TO-DATE > Task :app:compileDebugShaders NO-SOURCE > Task :app:generateDebugAssets UP-TO-DATE > Task :app:mergeDebugAssets UP-TO-DATE > Task :app:compressDebugAssets UP-TO-DATE > Task :app:processDebugJavaRes NO-SOURCE > Task :app:desugarDebugFileDependencies UP-TO-DATE > Task :app:mergeDebugJniLibFolders UP-TO-DATE > Task :app:mergeDebugNativeLibs NO-SOURCE > Task :app:stripDebugDebugSymbols NO-SOURCE > Task :app:validateSigningDebug UP-TO-DATE > Task :app:writeDebugAppMetadata UP-TO-DATE > Task :app:writeDebugSigningConfigVersions UP-TO-DATE > Task :app:checkDebugDuplicateClasses FAILED > Task :app:mergeDebugJavaResource FAILED FAILURE: Build completed with 3 failures. 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:processDebugMainManifest'. > Manifest merger failed with multiple errors, see logs * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:checkDebugDuplicateClasses'. > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable > Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class androidx.core.graphics.drawable.IconCompatParcelizer found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class androidx.core.internal.package-info found in modules core-1.7.0-runtime (androidx.core:core:1.7.0) and support-compat-28.0.0-runtime (com.android.support:support-compat:28.0.0) Duplicate class androidx.versionedparcelable.CustomVersionedParcelable found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.NonParcelField found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.ParcelField found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.ParcelImpl found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.ParcelImpl$1 found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.ParcelUtils found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcel found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcel$1 found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcel$ParcelException found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcelParcel found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcelStream found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcelStream$FieldBuffer found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcelable found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Duplicate class androidx.versionedparcelable.VersionedParcelize found in modules versionedparcelable-1.1.1-runtime (androidx.versionedparcelable:versionedparcelable:1.1.1) and versionedparcelable-28.0.0-runtime (com.android.support:versionedparcelable:28.0.0) Go to the documentation to learn how to Fix dependency resolution errors. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== 3: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mergeDebugJavaResource'. > A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction > 2 files found with path 'META-INF/androidx.core_core.version' from inputs: - C:\Users\wangsen\.gradle\caches\transforms-3\0b22a6b07b3e498281e2fdb9d93c9c6b\transformed\support-compat-28.0.0\jars\classes.jar - C:\Users\wangsen\.gradle\caches\transforms-3\0212d0c0c0b99c5d00c15a82a811f4d1\transformed\core-1.7.0\jars\classes.jar Adding a packagingOptions block may help, please refer to https://developer.android.com/reference/tools/gradle-api/7.4/com/android/build/api/dsl/ResourcesPackagingOptions for more information * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. ============================================================================== * Get more help at https://help.gradle.org BUILD FAILED in 436ms 22 actionable tasks: 3 executed, 19 up-to-date


