Xcode 10: unable to attach DB error

error: accessing build database xcode 11
error the use of xcframeworks is not supported in the legacy build system
command phasescriptexecution failed with a nonzero exit code
unable to attach db unable to open database unable to open database file

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

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):

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)

This probably unrelated, but I noticed that new Xcode 10 build system flags duplicated Copy Bundle Resource Info.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.

Does anyone have any idea what might be wrong?

Okay, seems like I managed to solve it. I was having /bin/sh script in Build Phases that was trying to build fat static library. In the script, I had OBJROOT path set like this:

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:

OBJROOT="${OBJROOT}/DependentBuilds"

After that, xcodebuild manages to build this target without issues with new build system introduced in 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


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

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 "${1}" \
    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 "${1}" "${2}" -output "${3}"
}

# 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_library method in this line:

OBJROOT="${OBJROOT}" \

Changing that line to:

OBJROOT="${OBJROOT}/DependantBuilds" \

solves the issue for me.

Running into "Error: unable to attach DB: accessing build database , Possibly there are two concurrent builds running in the same filesystem location" multiple times a day with Xcode 10. 1. andreyz changed the title [Xcode 10 beta 1] Possibly there are two concurrent builds running in the same filesystem location [Xcode 10 beta 4] Possibly there are two concurrent builds running in the same filesystem location Jul 25, 2018

Open XCode File->Project Settings

Build System->Legacy Build System

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

Xcode 10: unable to attach DB error, When updating to Xcode 10, iOS static library target fails to build. Way how I am trying to build it is following: xcodebuild -target TargetName -configuration  CartoonSmart.com Sep 30, 2016 10:53 AM (in response to Jacquesmarque) Unhook your device, plug it back in and usually that fixes it. You could also try going to Product (hold down Option Key) and choose Clean Build Folder.

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=NO in your xcodebuild command.

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

[run_tests] error msg: "Possibly there are two concurrent builds , I am not sure, but it looks like xcodebuild runs twice. [10:42:40]: ▸ Testing failed​: [10:42:40]: ▸ unable to attach DB: error: accessing build  iOS Xcode 10 How to fix broken “New build system” - build.db: database is locked Possibly there are two concurrent builds Ask Question Asked 1 year, 2 months ago

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

 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

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

Step 1 is to Detect RECURSION and stop them

[Xcode 10 beta 4] Possibly there are two concurrent builds running , Checked out e73f2f4 commit & tried building same project on Xcode 10 description Build system information error: unable to attach DB: error:  When updating to Xcode 10, iOS static library target fails to build. Way how I am trying to build it is following: xcodebuild - target TargetName - configuration Release clean build

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 -target parameter for the -scheme parameter in your xcodebuild command like:

xcodebuild -scheme SchemeName -configuration Release clean build

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

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

Xcode 10: unable to attach DB error, Xcode 10: unable to attach DB error. Multi tool use. 18. 6. When updating to Xcode 10, iOS static library target fails to build. Way how I am trying  GO to the folder r where you have stored mdf file. select file-> Right click ->click on . give full permissions to file for logged in user Security. Posted 6-Mar-13 23:31pm. Sharath.Mitte 23-May-14 15:52pm. thanks amol_B, it works for me:) satish kankerwal 19-Aug-15 8:59am. S.N.Ramkumar 18-Dec-19 9:50am. #N#vote 1 vote 2 vote 3 vote 4 vote 5.

Xcode 10: unable to attach DB error, Xcode 10: unable to attach DB error. Multi tool use. 21. 7. When updating to Xcode 10, iOS static library target fails to build. Way how I am trying  Summary. SQL Server sets database file access permissions when a database is attached or detached using a Windows login. This behavior is not applicable when using a SQL login to attach or detach a database as the SQL login will be using the Database Engine Service SID for the operation.

Xcode10 error: unable to attach DB: error: accessing build database , When updating to Xcode 10, iOS static library target fails to build. Way how I am trying to build it is following: Attach a Database. 10/24/2016; 6 minutes to read +5; In this article. APPLIES TO: SQL Server Azure SQL Database Azure Synapse Analytics (SQL DW) Parallel Data Warehouse This topic describes how to attach a database in SQL Server 2019 (15.x) by using SQL Server Management Studio or Transact-SQL.

Comments
  • Thanks for adding your solution. I was getting caught up on this as well.
  • Can you add more details, please. Perhaps you could add a copy of your script so others can see how you are using this variable and why the wrong path was creating this issue. Thanks
  • @TMin Added it to my answer. Hope it helps you.
  • Unfortunately that did not solve the issue for me (I didn't use ${OBJROOT} in my project)
  • In my case I was having an error "error: accessing build database .../Build/Intermediates.noindex/XCBuildData/build.db: disk I/O error", I added the "OBJROOT" parameter and it solved my issue. Thanks!
  • Can anyone explain to me the difference it is making?
  • I am actually using this in some of my build scripts, just forgot to update my answer with these instructions as well. Thanks for mentioning this solution, it's nice one, I like it.
  • This had seemed to work to remove the 'database is locked Possibly there are two concurrent builds running in the same filesystem location', however I'm faced with 'error: error: accessing build database "/Users/MyFolder/XCBuildData/build.db": disk I/O error', Any ideas guys?
  • What do you mean by RECURSION? And how do we stop it? Thanks.
  • Pretty interesting. Nothing comes up to my mind which might be causing this in your case. Thanks for sharing the solution!