<div dir="ltr">Looks good to me.<br><br><div class="gmail_quote"><div dir="ltr">Le mer. 31 mai 2017 à 01:50, Robert Mourning <<a href="mailto:robedmo.git@gmail.com" target="_blank">robedmo.git@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If local.properties exists but has been modified since last build,<br>
it might need to be changed to contain appropriate android sdk/ndk paths.<br>
For example, Android Studio will automatically modify local.properties<br>
if the project is opened in an environment with a different sdk location.<br>
<br>
Supports the following operations:<br>
- create a new local.properties if none exists, same as previous commit.<br>
- append sdk.dir and ndk.dir lines if none are found in existing file.<br>
- if existing file has incorrect sdk/ndk values, or has multiple entries<br>
for either, those lines will be replaced with a single one for each of<br>
sdk.dir and ndk.dir.<br>
<br>
---<br>
compile.sh | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----<br>
1 file changed, 54 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/compile.sh b/compile.sh<br>
index b8c32c1..2a888fe 100755<br>
--- a/compile.sh<br>
+++ b/compile.sh<br>
@@ -153,10 +153,60 @@ if [ ! -f gradle.properties ]; then<br>
echo storepwd=android >> gradle.properties<br>
fi<br>
fi<br>
-if [ ! -f local.properties ]; then<br>
- echo sdk.dir=$ANDROID_SDK > local.properties<br>
- echo ndk.dir=$ANDROID_NDK >> local.properties<br>
-fi<br>
+<br>
+init_local_props() {<br>
+ (<br>
+ # initialize the local.properties file,<br>
+ # or fix it if it was modified (by Android Studio, for example).<br>
+ echo_props() {<br>
+ echo "sdk.dir=$ANDROID_SDK"<br>
+ echo "ndk.dir=$ANDROID_NDK"<br>
+ }<br>
+ # first check if the file just needs to be created for the first time<br>
+ if [ ! -f "$1" ]; then<br>
+ echo_props > "$1"<br>
+ return 0<br>
+ fi<br>
+ # check for lines setting the SDK directory<br>
+ sdk_line_start="^sdk\.dir="<br>
+ total_sdk_count=`grep -c "${sdk_line_start}" "$1"`<br>
+ good_sdk_count=`grep -c "${sdk_line_start}${ANDROID_SDK}\$" "$1"`<br>
+ # check for lines setting the NDK directory<br>
+ ndk_line_start="^ndk\.dir="<br>
+ total_ndk_count=`grep -c "${ndk_line_start}" "$1"`<br>
+ good_ndk_count=`grep -c "${ndk_line_start}${ANDROID_NDK}\$" "$1"`<br>
+ # if one of each is found and both match the environment vars, no action needed<br>
+ if [ "$total_sdk_count" -eq "1" -a "$good_sdk_count" -eq "1" \<br>
+ -a "$total_ndk_count" -eq "1" -a "$good_ndk_count" -eq "1" ]<br>
+ then<br>
+ return 0<br>
+ fi<br>
+ # if neither property is set they can simply be appended to the file<br>
+ if [ "$total_sdk_count" -eq "0" -a "$total_ndk_count" -eq "0" ]; then<br>
+ echo_props >> "$1"<br>
+ return 0<br>
+ fi<br>
+ # if a property is set incorrectly or too many times,<br>
+ # remove all instances of both properties and append correct ones.<br>
+ replace_props() {<br>
+ temp_props="$1.tmp"<br>
+ while IFS= read -r LINE || [ -n "$LINE" ]; do<br>
+ line_sdk_dir="${LINE#sdk.dir=}"<br>
+ line_ndk_dir="${LINE#ndk.dir=}"<br>
+ if [ "x$line_sdk_dir" = "x$LINE" -a "x$line_ndk_dir" = "x$LINE" ]; then<br>
+ echo "$LINE"<br>
+ fi<br>
+ done <"$1" >"$temp_props"<br>
+ echo_props >> "$temp_props"<br>
+ mv -f -- "$temp_props" "$1"<br>
+ }<br>
+ echo "local.properties: Contains incompatible sdk.dir and/or ndk.dir properties. Replacing..."<br>
+ replace_props "$1"<br>
+ echo "local.properties: Finished replacing sdk.dir and/or ndk.dir with current environment variables."<br>
+ )<br>
+}<br>
+init_local_props local.properties || { echo "Error initializing local.properties"; exit $?; }<br>
+<br>
if [ ! -d "$ANDROID_SDK/licenses" ]; then<br>
mkdir "$ANDROID_SDK/licenses"<br>
echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"<br>
--<br>
2.7.4<br>
<br>
_______________________________________________<br>
Android mailing list<br>
<a href="mailto:Android@videolan.org" target="_blank">Android@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/android" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/android</a><br>
</blockquote></div></div>