mirror of
https://github.com/opencv/opencv.git
synced 2024-11-24 03:00:14 +08:00
Merge pull request #24956 from asmorkalov:as/android_build_offline
Added offline option for Android builds #24956 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
parent
250cfe81c5
commit
8850a8219e
@ -5,6 +5,7 @@ echo "OpenCV Android SDK path: ${SDK_DIR}"
|
||||
|
||||
ANDROID_HOME=${ANDROID_HOME:-${ANDROID_SDK_ROOT:-${ANDROID_SDK?Required ANDROID_HOME/ANDROID_SDK/ANDROID_SDK_ROOT}}}
|
||||
ANDROID_NDK=${ANDROID_NDK_HOME-${ANDROID_NDK:-${NDKROOT?Required ANDROID_NDK_HOME/ANDROID_NDK/NDKROOT}}}
|
||||
OPENCV_GRADLE_VERBOSE_OPTIONS=${OPENCV_GRADLE_VERBOSE_OPTIONS:-'-i'}
|
||||
|
||||
echo "Android SDK: ${ANDROID_HOME}"
|
||||
echo "Android NDK: ${ANDROID_NDK}"
|
||||
@ -35,7 +36,7 @@ echo "ndk.dir=${ANDROID_NDK}" > "test-gradle/samples/local.properties"
|
||||
echo "cmake.dir=$(dirname $(dirname $(which cmake)))" >> "test-gradle/samples/local.properties"
|
||||
|
||||
echo "Run gradle ..."
|
||||
(cd "test-gradle/samples"; ./gradlew -i assemble)
|
||||
(cd "test-gradle/samples"; ./gradlew ${OPENCV_GRADLE_VERBOSE_OPTIONS} assemble)
|
||||
|
||||
echo "#"
|
||||
echo "# Done!"
|
||||
|
@ -6,6 +6,7 @@ echo "Use local maven repo from $LOCAL_MAVEN_REPO"
|
||||
|
||||
ANDROID_HOME=${ANDROID_HOME:-${ANDROID_SDK_ROOT:-${ANDROID_SDK?Required ANDROID_HOME/ANDROID_SDK/ANDROID_SDK_ROOT}}}
|
||||
ANDROID_NDK=${ANDROID_NDK_HOME-${ANDROID_NDK:-${NDKROOT?Required ANDROID_NDK_HOME/ANDROID_NDK/NDKROOT}}}
|
||||
OPENCV_GRADLE_VERBOSE_OPTIONS=${OPENCV_GRADLE_VERBOSE_OPTIONS:-'-i'}
|
||||
|
||||
echo "Android SDK: ${ANDROID_HOME}"
|
||||
echo "Android NDK: ${ANDROID_NDK}"
|
||||
@ -40,7 +41,7 @@ sed -i "s/opencv_source = 'sdk_path'/opencv_source = 'maven_local'/g" test-gradl
|
||||
sed -i "s+opencv_maven_path = '<path_to_maven_repo>'+opencv_maven_path = 'file\\://$LOCAL_MAVEN_REPO'+g" test-gradle-aar/settings.gradle
|
||||
|
||||
echo "Run gradle ..."
|
||||
(cd "test-gradle-aar"; ./gradlew -i assemble)
|
||||
(cd "test-gradle-aar"; ./gradlew ${OPENCV_GRADLE_VERBOSE_OPTIONS} assemble)
|
||||
|
||||
echo "#"
|
||||
echo "# Done!"
|
||||
|
@ -5,6 +5,7 @@ echo "OpenCV Android SDK path: ${SDK_DIR}"
|
||||
|
||||
ANDROID_HOME=${ANDROID_HOME:-${ANDROID_SDK_ROOT:-${ANDROID_SDK?Required ANDROID_HOME/ANDROID_SDK/ANDROID_SDK_ROOT}}}
|
||||
ANDROID_NDK=${ANDROID_NDK_HOME-${ANDROID_NDK:-${NDKROOT?Required ANDROID_NDK_HOME/ANDROID_NDK/NDKROOT}}}
|
||||
OPENCV_GRADLE_VERBOSE_OPTIONS=${OPENCV_GRADLE_VERBOSE_OPTIONS:-'-i'}
|
||||
|
||||
echo "Android SDK: ${ANDROID_HOME}"
|
||||
echo "Android NDK: ${ANDROID_NDK}"
|
||||
@ -35,7 +36,7 @@ echo "ndk.dir=${ANDROID_NDK}" > "aar-build/samples/local.properties"
|
||||
echo "cmake.dir=$(dirname $(dirname $(which cmake)))" >> "aar-build/samples/local.properties"
|
||||
|
||||
echo "Run gradle ..."
|
||||
(cd "aar-build/samples"; ./gradlew ${OPENCV_GRADLE_VERBOSE_OPTIONS:--i} opencv:publishReleasePublicationToMyrepoRepository)
|
||||
(cd "aar-build/samples"; ./gradlew ${OPENCV_GRADLE_VERBOSE_OPTIONS} opencv:publishReleasePublicationToMyrepoRepository)
|
||||
|
||||
mkdir "maven_repo"
|
||||
cp -r aar-build/sdk/build/repo/* ./maven_repo/
|
||||
|
@ -117,10 +117,10 @@ def main(args):
|
||||
|
||||
print("Running gradle assembleRelease...")
|
||||
# Running gradle to build the Android project
|
||||
subprocess.run(["./gradlew", "assembleRelease"],
|
||||
shell=False,
|
||||
cwd=ANDROID_PROJECT_DIR,
|
||||
check=True)
|
||||
cmd = ["./gradlew", "assembleRelease"]
|
||||
if args.offline:
|
||||
cmd = cmd + ["--offline"]
|
||||
subprocess.run(cmd, shell=False, cwd=ANDROID_PROJECT_DIR, check=True)
|
||||
|
||||
print("Adding libs to AAR...")
|
||||
# The created AAR package doesn't contain C++ shared libs.
|
||||
@ -146,20 +146,20 @@ def main(args):
|
||||
shutil.copy(final_aar_path, path.join(ANDROID_PROJECT_DIR, "OpenCV/opencv-release.aar"))
|
||||
|
||||
print("Creating a maven repo from project sources (with sources jar and javadoc jar)...")
|
||||
subprocess.run(["./gradlew", "publishReleasePublicationToMyrepoRepository"],
|
||||
shell=False,
|
||||
cwd=ANDROID_PROJECT_DIR,
|
||||
check=True)
|
||||
cmd = ["./gradlew", "publishReleasePublicationToMyrepoRepository"]
|
||||
if args.offline:
|
||||
cmd = cmd + ["--offline"]
|
||||
subprocess.run(cmd, shell=False, cwd=ANDROID_PROJECT_DIR, check=True)
|
||||
|
||||
os.makedirs(path.join(FINAL_REPO_PATH, "org/opencv"), exist_ok=True)
|
||||
shutil.move(path.join(ANDROID_PROJECT_DIR, "OpenCV/build/repo/org/opencv", MAVEN_PACKAGE_NAME),
|
||||
path.join(FINAL_REPO_PATH, "org/opencv", MAVEN_PACKAGE_NAME))
|
||||
|
||||
print("Creating a maven repo from modified AAR (with cpp libraries)...")
|
||||
subprocess.run(["./gradlew", "publishModifiedPublicationToMyrepoRepository"],
|
||||
shell=False,
|
||||
cwd=ANDROID_PROJECT_DIR,
|
||||
check=True)
|
||||
cmd = ["./gradlew", "publishModifiedPublicationToMyrepoRepository"]
|
||||
if args.offline:
|
||||
cmd = cmd + ["--offline"]
|
||||
subprocess.run(cmd, shell=False, cwd=ANDROID_PROJECT_DIR, check=True)
|
||||
|
||||
# Replacing AAR from the first maven repo with modified AAR from the second maven repo
|
||||
shutil.copytree(path.join(ANDROID_PROJECT_DIR, "OpenCV/build/repo/org/opencv", MAVEN_PACKAGE_NAME),
|
||||
@ -176,6 +176,7 @@ if __name__ == "__main__":
|
||||
parser.add_argument('--java_version', default="1_8")
|
||||
parser.add_argument('--ndk_location', default="")
|
||||
parser.add_argument('--cmake_location', default="")
|
||||
parser.add_argument('--offline', action="store_true", help="Force Gradle use offline mode")
|
||||
args = parser.parse_args()
|
||||
|
||||
main(args)
|
||||
|
@ -147,11 +147,11 @@ def main(args):
|
||||
add_printing_linked_libs(sdk_dir, opencv_libs)
|
||||
|
||||
print("Running gradle assembleRelease...")
|
||||
cmd = ["./gradlew", "assembleRelease"]
|
||||
if args.offline:
|
||||
cmd = cmd + ["--offline"]
|
||||
# Running gradle to build the Android project
|
||||
subprocess.run(["./gradlew", "assembleRelease"],
|
||||
shell=False,
|
||||
cwd=ANDROID_PROJECT_DIR,
|
||||
check=True)
|
||||
subprocess.run(cmd, shell=False, cwd=ANDROID_PROJECT_DIR, check=True)
|
||||
|
||||
# The created AAR package contains only one empty libtemplib.a library.
|
||||
# We need to add OpenCV libraries manually.
|
||||
@ -217,20 +217,20 @@ def main(args):
|
||||
shutil.copy(final_aar_path, path.join(ANDROID_PROJECT_DIR, "OpenCV/opencv-release.aar"))
|
||||
|
||||
print("Creating a maven repo from project sources (with sources jar and javadoc jar)...")
|
||||
subprocess.run(["./gradlew", "publishReleasePublicationToMyrepoRepository"],
|
||||
shell=False,
|
||||
cwd=ANDROID_PROJECT_DIR,
|
||||
check=True)
|
||||
cmd = ["./gradlew", "publishReleasePublicationToMyrepoRepository"]
|
||||
if args.offline:
|
||||
cmd = cmd + ["--offline"]
|
||||
subprocess.run(cmd, shell=False, cwd=ANDROID_PROJECT_DIR, check=True)
|
||||
|
||||
os.makedirs(path.join(FINAL_REPO_PATH, "org/opencv"), exist_ok=True)
|
||||
shutil.move(path.join(ANDROID_PROJECT_DIR, "OpenCV/build/repo/org/opencv", MAVEN_PACKAGE_NAME),
|
||||
path.join(FINAL_REPO_PATH, "org/opencv", MAVEN_PACKAGE_NAME))
|
||||
|
||||
print("Creating a maven repo from modified AAR (with cpp libraries)...")
|
||||
subprocess.run(["./gradlew", "publishModifiedPublicationToMyrepoRepository"],
|
||||
shell=False,
|
||||
cwd=ANDROID_PROJECT_DIR,
|
||||
check=True)
|
||||
cmd = ["./gradlew", "publishModifiedPublicationToMyrepoRepository"]
|
||||
if args.offline:
|
||||
cmd = cmd + ["--offline"]
|
||||
subprocess.run(cmd, shell=False, cwd=ANDROID_PROJECT_DIR, check=True)
|
||||
|
||||
# Replacing AAR from the first maven repo with modified AAR from the second maven repo
|
||||
shutil.copytree(path.join(ANDROID_PROJECT_DIR, "OpenCV/build/repo/org/opencv", MAVEN_PACKAGE_NAME),
|
||||
@ -249,6 +249,7 @@ if __name__ == "__main__":
|
||||
parser.add_argument('--java_version', default="1_8")
|
||||
parser.add_argument('--ndk_location', default="")
|
||||
parser.add_argument('--cmake_location', default="")
|
||||
parser.add_argument('--offline', action="store_true", help="Force Gradle use offline mode")
|
||||
args = parser.parse_args()
|
||||
|
||||
main(args)
|
||||
|
Loading…
Reference in New Issue
Block a user