Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
268 views
in Technique[技术] by (71.8m points)

ios - 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 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...