// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Set the list of Android ABIs depending on whether we the ANDROID_NDK_HOME
// environment variable contains the text 'r16b' in it. This will generally only
// occur during C++ packaging, which uses /tmp/android-ndk-r16b as the NDK
// directory.  When using this NDK version, add a few additional ABIs that are
// only supported in r16b and earlier.

android {
  defaultConfig {
    ndk {
      // Default list of ABIs available in up-to-date NDK.
      abiFilters "x86", "armeabi-v7a", "arm64-v8a", "x86_64"

      if (System.getenv("ANDROID_NDK_HOME") != null && (
          System.getenv("ANDROID_NDK_HOME").contains("r16b") ||
          System.getenv("ANDROID_NDK_HOME").contains("r11c"))) {
        // Deprecated ABIs are added to the list when building using older NDKs only.
        // Rather than an exhaustive list, we only support r11c and r16b.
        abiFilters.add("armeabi")
        abiFilters.add("mips")
        abiFilters.add("mips64")
        if (System.getenv("ANDROID_NDK_HOME").contains("r11c")) {
          abiFilters.add("armeabi-v7a-hard")  // Removed after r11c.
        }
      }
    }
  }
}

