<?xml version="7.0.4" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you 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.
-->

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
        xmlns:android="http://schemas.android.com/apk/res/android"
        id="cordova-plugin-appsflyer-sdk"
        version="7.0.4-rc1">
    <name>AppsFlyer</name>
    <description>Cordova Plugin AppsFlyer</description>
    <license>Apache 2.0</license>
    <keywords>cordova,appsflyer</keywords>
    <repo>https://github.com/AppsFlyerSDK/appsflyer-cordova-plugin.git</repo>
    <engines>
        <engine name="cordova" version=">=12.0.0"/>
        <!-- Kotlin and Swift build support require these platform minimums; below them `cordova.exec` calls hang forever instead of failing loudly. Matches the versions this repo actually builds/tests against (test-app/package.json). -->
        <engine name="cordova-android" version=">=13.0.0"/>
        <engine name="cordova-ios" version=">=7.1.1"/>
    </engines>

    <js-module src="www/appsflyer.js" name="appsflyer">
        <clobbers target="window.plugins.appsFlyer"/>
    </js-module>


    <!-- android -->
    <platform name="android">
        <!-- cordova-android only applies the kotlin-android Gradle plugin (and wires up the
             src/main/kotlin source set / kotlinc task) when this preference is set; it is NOT
             auto-detected from the presence of .kt source files. Without it, AppsFlyerPlugin.kt
             is silently skipped by the build (no Gradle error), so `cordova.exec` calls into it
             hang forever waiting on a native handler that was never registered. -->
        <config-file target="config.xml" parent="/*">
            <preference name="GradlePluginKotlinEnabled" value="true"/>
        </config-file>
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="AppsFlyerPlugin">
                <param name="android-package" value="com.appsflyer.cordova.plugin.AppsFlyerPlugin"/>
            </feature>
        </config-file>
        <config-file target="AndroidManifest.xml" parent="/*">
            <uses-permission android:name="android.permission.INTERNET"/>
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
            <uses-permission android:name="com.google.android.gms.permission.AD_ID" />
        </config-file>

        <!-- cordova-android's source-file installer only special-cases the ".java" extension
             (pluginHandlers.js getInstallDestination); a ".kt" target-dir without the "app/"
             prefix falls through to app/src/main/<target-dir>, landing outside both the default
             Java source set and the src/main/kotlin dir cordovaAF's build.gradle registers. That
             leaves the class uncompiled silently (Gradle doesn't error on an unreferenced source
             dir), so `cordova.exec` calls into AppsFlyerPlugin hang forever: Cordova's
             PluginManager fails ClassNotFoundException and never calls back. Target the app/
             directory explicitly so the installer copies it verbatim into the real Kotlin
             source set. -->
        <source-file src="src/android/com/appsflyer/cordova/plugin/AppsFlyerPlugin.kt"
                     target-dir="app/src/main/kotlin/com/appsflyer/cordova/plugin"/>
        <framework src="src/android/cordovaAF.gradle" custom="true" type="gradleReference"/>
        <hook type="after_prepare" src="hooks/af_strict_mode.js"/>
    </platform>


    <!-- ios -->
    <platform name="ios">
        <config-file target="config.xml" parent="/*">
            <feature name="AppsFlyerPlugin">
                <param name="ios-package" value="AppsFlyerPlugin"/>
            </feature>
        </config-file>
        <!-- This plugin ships Swift source; cordova-ios doesn't set SWIFT_VERSION on a project
             that had none of its own, and Xcode then refuses to build at all. -->
        <hook type="after_prepare" src="hooks/af_set_swift_version.js"/>
        <hook type="after_prepare" src="hooks/af_strict_mode.js"/>
        <source-file src="src/ios/AppsFlyerX+AppController.m"/>
        <source-file src="src/ios/AppsFlyerPlugin.swift"/>
        <source-file src="src/ios/AppsFlyerAttribution.swift"/>
        <podspec>
            <config>
            </config>
            <pods use-frameworks="true">
               <pod name="AppsFlyerRPC" spec="7.0.41"/>
            </pods>
        </podspec>
    </platform>

</plugin>
