0

在我的项目中添加了一个 Android 库模块后,该应用程序已停止与 API 通信,并且 Android Studio 完全冻结并且无法调试,因此没有错误消息。

我猜我在库中实现构建类型和产品风格的方式应该改变。

我正在尝试继续运行StagingDebug build variant

这就是我的应用程序 build.gradle 的样子

buildTypes {
        debug {
            debuggable true
        }
        debugProxy {
            initWith debug
            buildConfigField "String", "LOCAL_DEV_PROXY_IP", "\"${getIP()}\""
            buildConfigField "Integer", "LOCAL_DEV_PROXY_PORT", '8888'
            buildConfigField "Boolean", "LOCAL_DEV_PROXY_ENABLED", 'true'
        }
        release {
            debuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            if (keystoreProperties) signingConfig signingConfigs.config

            firebaseAppDistribution {
                serviceCredentialsFile = rootProject.file("google-credentials.json").path
                groups = "qa" // QA tester group defined in Firebase console
            }
        }
    }

    productFlavors {
            dev { // local dev environment
                dimension "environment"
                applicationIdSuffix ".dev"
                testApplicationId "com.xx.xx.dev.test"
                versionName android.defaultConfig.versionName + "-dev"
                buildConfigField "Boolean", "LOCAL_DEV_MODE_ENABLED", 'true'
            }
            dump { // local dev "dump" environment, for debugging with production database dumps
                dimension "environment"
                applicationIdSuffix ".dev"
                testApplicationId "com.xx.xxx.dev.test"
                versionName android.defaultConfig.versionName + "-dev-dump"
                buildConfigField "Boolean", "LOCAL_DEV_MODE_ENABLED", 'true'
            }
            staging {
                dimension "environment"
                applicationIdSuffix ".staging"
                testApplicationId "com.xx.xxx.staging.test"
                versionName android.defaultConfig.versionName + "-staging"
            }
            qa {
                dimension "environment"
                applicationIdSuffix ".qa"
                testApplicationId "com.xx.xxx.qa.test"
                versionName android.defaultConfig.versionName + "-qa"
            }
            production {
                dimension "environment"
            }
        }

库只有构建类型

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debugProxy {
            initWith debug
            buildConfigField "String", "LOCAL_DEV_PROXY_IP", "\"${getIP()}\""
            buildConfigField "Integer", "LOCAL_DEV_PROXY_PORT", '8888'
            buildConfigField "Boolean", "LOCAL_DEV_PROXY_ENABLED", 'true'
        }
    }

Library buildTypes 和 productflavors 应该如何更改为。

谢谢

R

编辑

`getIP` function is added into both app and library

/**
 * Attempt to find local network address for use with web proxy
 *
 * Inspired/copied from: http://jeremie-martinez.com/2015/05/05/inject-host-gradle/
 *
 * @return String with IP address of local network address, or empty string if none found
 */
def getIP() {
    // Print found local IP address fallback used if no network interface with valid address is found (useful for debugging)
//    println("Local IP Address fallback will be: " + InetAddress.getLocalHost() != null ? InetAddress.getLocalHost().getHostAddress() : "unknown")

    InetAddress result = null
    Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces()

    while (interfaces.hasMoreElements()) {
        NetworkInterface anInterface = interfaces.nextElement()
//        println("Interface name: " + anInterface.displayName);
        Enumeration<InetAddress> addresses = anInterface.getInetAddresses()

        while ((anInterface.displayName.length() < 4 || anInterface.displayName.substring(0, 4) != "vbox") && addresses.hasMoreElements()) {
            InetAddress address = addresses.nextElement()

            // Print found IP addresses (useful for debugging)
//            println("Possible IP Address discovered: " + address.getHostAddress())

            // Ensure no loopback address gets used
            if (!address.isLoopbackAddress()) {
                // Try to use an IPv4 site local address, but not in the 172.x.x.x range (docker subnets)
                if (address.isSiteLocalAddress() && address.getHostAddress().substring(0, 4) != "172.") {
                    println("IP Address of local machine found: " + address.getHostAddress())
                    return address.getHostAddress()
                }
            }
        }
    }
    return result != null ? result.getHostAddress() : "" /*InetAddress.getLocalHost().getHostAddress()*/
}
4

0 回答 0