ios Xcode 10:无法附加数据库错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51153525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:45:14  来源:igfitidea点击:

Xcode 10: unable to attach DB error

iosxcodebuildxcode10

提问by uerceg

When updating to Xcode 10, iOS static library target fails to build. Way how I am trying to build it is following:

更新到 Xcode 10 时,iOS 静态库目标无法构建。我尝试构建它的方式如下:

xcodebuild -target TargetName -configuration Release clean build

With Xcode 9 everything runs smoothly, but when Xcode 10 is used for build, I am getting following error (after clean runs smoothly):

使用 Xcode 9 一切顺利,但是当使用 Xcode 10 进行构建时,我收到以下错误(在干净运行后):

note: Using new build system

note: Planning build

note: Constructing build description Build system information error: unable to attach DB: error: accessing build database "/Users/uerceg/random-path/build/XCBuildData/build.db": database is locked Possibly there are two concurrent builds running in the same filesystem location.

** BUILD FAILED **

** BUILD FAILED **

The following build commands failed: PhaseScriptExecution MultiPlatform\ Build /Users/uerceg/random-path/build/Library.build/Release-iphoneos/LibraryTarget.build/Script-9DE7C9021AE68FA5001556E5.sh (1 failure)

注意:使用新的构建系统

注意:规划构建

注意:构建构建描述构建系统信息错误:无法附加数据库:错误:访问构建数据库“/Users/uerceg/random-path/build/XCBuildData/build.db”:数据库被锁定可能有两个并发构建在运行相同的文件系统位置。

** 构建失败 **

** 构建失败 **

以下构建命令失败:PhaseScriptExecution MultiPlatform\ Build /Users/uerceg/random-path/build/Library.build/Release-iphoneos/LibraryTarget.build/Script-9DE7C9021AE68FA5001556E5.sh(1 次失败)

This probably unrelated, but I noticed that new Xcode 10 build system flags duplicated Copy Bundle ResourceInfo.plist files as errors, so I did make sure that there're no duplicated entries, but probably this error is not related to this fact.

这可能无关,但我注意到新的 Xcode 10 构建系统将重复的Copy Bundle ResourceInfo.plist 文件标记为错误,所以我确实确保没有重复的条目,但这个错误可能与这个事实无关。

Does anyone have any idea what might be wrong?

有谁知道可能有什么问题?

回答by uerceg

Okay, seems like I managed to solve it. I was having /bin/shscript in Build Phasesthat was trying to build fat static library. In the script, I had OBJROOTpath set like this:

好吧,看来我设法解决了它。我正在尝试构建胖静态库的/bin/sh脚本Build Phases。在脚本中,我OBJROOT设置了如下路径:

OBJROOT="${OBJROOT}"

Seems like Xcode 10 and new build system changed some paths on the way and this line was the source of the issue. It needs to be adjusted to:

似乎 Xcode 10 和新的构建系统在途中改变了一些路径,这一行是问题的根源。它需要调整为:

OBJROOT="${OBJROOT}/DependentBuilds"

After that, xcodebuildmanages to build this target without issues with new build system introduced in Xcode 10.

之后,xcodebuild通过 Xcode 10 中引入的新构建系统,设法构建此目标,而不会出现问题。

I didn't get to this solution by myself, big thanks to Matt Gallagher and his post in here: https://github.com/mattgallagher/CwlSignal/issues/24#issuecomment-396931001

我自己没有得到这个解决方案,非常感谢 Matt Gallagher 和他在这里的帖子:https: //github.com/mattgallagher/CwlSignal/issues/24#issuecomment-396931001



As requested by @TMin in comment, here's how my script looks like:

根据@TMin 在评论中的要求,我的脚本如下所示:

set -e

# If we're already inside this script then die
if [ -n "$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then
exit 0
fi
export RW_MULTIPLATFORM_BUILD_IN_PROGRESS=1

RW_FRAMEWORK_NAME=${PROJECT_NAME}
RW_INPUT_STATIC_LIB="lib${PROJECT_NAME}.a"
RW_FRAMEWORK_LOCATION="${BUILT_PRODUCTS_DIR}/static/${RW_FRAMEWORK_NAME}Sdk.framework"

function build_static_library {
    echo "1"
    echo "${BUILD_DIR}"
    # Will rebuild the static library as specified
    #     build_static_library sdk
    xcrun xcodebuild -project "${PROJECT_FILE_PATH}" \
    -target "${TARGET_NAME}" \
    -configuration "${CONFIGURATION}" \
    -sdk "" \
    ONLY_ACTIVE_ARCH=NO \
    BUILD_DIR="${BUILD_DIR}" \
    OBJROOT="${OBJROOT}" \
    BUILD_ROOT="${BUILD_ROOT}" \
    SYMROOT="${SYMROOT}" $ACTION
}

function make_fat_library {
    # Will smash 2 static libs together
    #     make_fat_library in1 in2 out
    xcrun lipo -create "" "" -output ""
}

# 1 - Extract the platform (iphoneos/iphonesimulator) from the SDK name
if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]; then
RW_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi

# 2 - Extract the version from the SDK
if [[ "$SDK_NAME" =~ ([0-9]+.*$) ]]; then
RW_SDK_VERSION=${BASH_REMATCH[1]}
else
echo "Could not find sdk version from SDK_NAME: $SDK_NAME"
exit 1
fi

# 3 - Determine the other platform
if [ "$RW_SDK_PLATFORM" == "iphoneos" ]; then
RW_OTHER_PLATFORM=iphonesimulator
else
RW_OTHER_PLATFORM=iphoneos
fi

# 4 - Find the build directory
if [[ "$BUILT_PRODUCTS_DIR" =~ (.*)$RW_SDK_PLATFORM$ ]]; then
RW_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${RW_OTHER_PLATFORM}"
else
echo "Could not find other platform build directory."
exit 1
fi

# Build the other platform.
build_static_library "${RW_OTHER_PLATFORM}${RW_SDK_VERSION}"

# If we're currently building for iphonesimulator, then need to rebuild
#   to ensure that we get both i386 and x86_64
if [ "$RW_SDK_PLATFORM" == "iphonesimulator" ]; then
build_static_library "${SDK_NAME}"
fi

# Join the 2 static libs into 1 and push into the .framework
make_fat_library "${BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}Sdk"

# Ensure that the framework is present in both platform's build directories
cp -a "${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}Sdk" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/static/${RW_FRAMEWORK_NAME}Sdk.framework/Versions/A/${RW_FRAMEWORK_NAME}Sdk"

# Copy the framework to the project directory
ditto "${RW_FRAMEWORK_LOCATION}" "${SRCROOT}/Frameworks/static/${RW_FRAMEWORK_NAME}Sdk.framework"

Problem is in build_static_librarymethod in this line:

问题出build_static_library在这一行的方法中:

OBJROOT="${OBJROOT}" \

Changing that line to:

将该行更改为:

OBJROOT="${OBJROOT}/DependantBuilds" \

solves the issue for me.

为我解决了这个问题。

回答by sharon ouyang

Open XCode File->Project Settings

打开 XCode 文件->项目设置

Build System->Legacy Build System

构建系统->传统构建系统

Configure XCode of version 10.0 project settings can solve the problem.

配置XCode 10.0版本项目设置即可解决问题。

回答by Shih Ken

If you use build script to build submodule's libraries like me. You also need to disable new build system in your build script explicitly by using -UseModernBuildSystem=NOin your xcodebuild command.

如果你像我一样使用构建脚本来构建子模块的库。您还需要通过-UseModernBuildSystem=NO在 xcodebuild 命令中使用来显式禁用构建脚本中的新构建系统。

For example:

例如:

xcodebuild -configuration "${CONFIGURATION}" -project "${PROJECT_NAME}.xcodeproj" -target "${TARGET_NAME}" -sdk "${OTHER_SDK_TO_BUILD}" ${ACTION} RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" SYMROOT="${SYMROOT}" -UseModernBuildSystem=NO

回答by Raj Maurya

Use this script it will it is working fine with new build system

使用这个脚本它会在新的构建系统中正常工作

# Step 1 search RECURSION and if detected stop "*/

if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"

UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal

# Step 2. Build Device and Simulator versions

xcodebuild -target logger ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"

xcodebuild -target logger-configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 -arch x86_64 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"

# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"

# Step 3. Create universal binary file using lipo
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}universal.a" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a"

# Last touch. copy the header files. Just for convenience
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/"

fi

before Xcode 10 build system uses single thread, but in Xcode 10 usees new build system with multiple threads, so every time you run your build Xcode run button this script

在 Xcode 10 构建系统使用单线程之前,但在 Xcode 10 中使用具有多线程的新构建系统,因此每次运行构建时 Xcode 运行按钮此脚本

 xcodebuild -target logger ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}".

will call one more time for build so on, that will create RECURSION

将再调用一次构建等等,这将创建 RECURSION

Don't forgot to end you Script With (fi) its end of IF condition

不要忘记以 (fi) 结束 IF 条件结束您的脚本

Step 1 is to Detect RECURSION and stop them

第 1 步是检测 RECURSION 并阻止它们

回答by Delfín

If you want to keep the XCode 10 default build system but still running your build outside of the IDE (in a CI machine for instance), just replace your -targetparameter for the -schemeparameter in your xcodebuildcommand like:

如果您想保留 XCode 10 默认构建系统但仍然在 IDE 之外运行您的构建(例如在 CI 机器中),只需将您的-target参数替换为命令中的-scheme参数,xcodebuild例如:

xcodebuild -scheme SchemeName -configuration Release clean build

Thanks to thispost from 2015 that talks about a very similar problem and it gave me the hint to solve this problem. As the same author says,

感谢这篇2015 年的帖子,它讨论了一个非常相似的问题,它给了我解决这个问题的提示。正如同一作者所说,

I would hazard a guess, that xcodebuildwithout a scheme goes wrongly through the "modern build system", giving the mentioned error

我会冒险猜测,如果xcodebuild没有计划,“现代构建系统”就会出错,从而导致上述错误

回答by Dmytro Turkov

I have the same issues and try everything from the hints but this error still continues. Sometimes the project is built, next time there is no and error. And the solution that helps me is to edit scheme and switch off Parallelize Build. After that everything works fine.

我有同样的问题并尝试从提示中进行的所有操作,但此错误仍然存​​在。有时候项目建好了,下次就没有和错误了。帮助我的解决方案是编辑方案并关闭并行构建。之后一切正常。

回答by Adam Waite

Adding a Clean derived datastep in my build scripts (before an Xcode build) seems to fix the problem for me.

在我的构建脚本中(在 Xcode 构建之前)添加一个Clean 派生数据步骤似乎为我解决了这个问题。

Not sure if it's related, but my project uses Realm (installed with CocoaPods). This is the GitHub issue that inspired the "fix" -> https://github.com/realm/realm-cocoa/issues/5812.

不确定它是否相关,但我的项目使用 Realm(与 CocoaPods 一起安装)。这是启发“修复”的 GitHub 问题 -> https://github.com/realm/realm-cocoa/issues/5812