[英]JQuery POST request to Laravel route is throwing errors but works fine when I directly access
[英]App works fine, when testing directly from Android Studio, but not when installed as APK on the Device
我已经编写了一个通过 PHP/Mysqli 和 Retrofit 登录的应用程序。 当我直接从 Android Studio 测试智能手机上的应用程序时(单击“运行”-按钮),登录工作正常!
但是当我生成一个签名的 apk 然后将它安装在我的智能手机上时,登录不起作用。 我想我的 MySQL 数据库的 Internet 连接有问题?
我已经搜索并发现,我应该设置一个 network_security_configuration。 我已经设置并给出了 <uses-permission... INTERNET。 但它不起作用,只有当我直接从我的设备上的 Android Studio 测试时。
问题的解决方案是什么? 我为 PHP 脚本 ( https://domain.tld/login.php ) 使用了到我自己的 Web 服务器的 HTTPS/SSL 连接。
这是我的网络配置:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
和 Android 清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.uwbeinternational.weatherapp">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.UwBeWeatherApp"
android:networkSecurityConfig="@xml/network_security_config">
这里我使用 Retrofit 来检查 Login-Credentials:
class RetrofitClient {
private fun getRetrofitClient(): Retrofit {
return Retrofit.Builder()
.baseUrl("https://uwbeinternational.org/")
.addConverterFactory(GsonConverterFactory.create())
.build()
}
fun getInstance(): ApiClient {
return getRetrofitClient().create(ApiClient::class.java)
}
}
和 ApiClient:
interface ApiClient {
@FormUrlEncoded
@POST("android/login_service.php")
fun login(
@Field("post_username") username : String,
@Field("post_password") password : String
): Call<ResponseLogin>
}
这是 Proguard-Rules 的问题。 所以,我现在将这些行添加到 proguard.pro 文件中:
#Retrofit2
-keep class com.uwbeinternational.weatherapp.** { *; }
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**
现在它完美运行!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.