打包后安装到手机上不显示数据

来源:18-4 打包发布Flutter Android应用-2

慕尼黑3223685

2022-01-03

结果和 https://coding.imooc.com/learn/questiondetail/g5J7RPqEjVNP8Zw1.html 这个问题是一样的 接口是https的 真机调试没问题
手机是Android10 荣耀9x EMUI 是10.1.0

build.gradle 如下
def localProperties = new Properties()
def localPropertiesFile = rootProject.file(‘local.properties’)
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader(‘UTF-8’) { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty(‘flutter.sdk’)
if (flutterRoot == null) {
throw new GradleException(“Flutter SDK not found. Define location with flutter.sdk in the local.properties file.”)
}

def flutterVersionCode = localProperties.getProperty(‘flutter.versionCode’)
if (flutterVersionCode == null) {
flutterVersionCode = ‘1’
}

def flutterVersionName = localProperties.getProperty(‘flutter.versionName’)
if (flutterVersionName == null) {
flutterVersionName = ‘1.0’
}

apply plugin: 'com.android.application’
apply plugin: 'kotlin-android’
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file(‘key.properties’)
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
compileSdkVersion 30

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.trip_app"

// minSdkVersion flutter.minSdkVersion
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName flutterVersionName
}

signingConfigs {
    release {
        keyAlias keystoreProperties['keyAlias']
        keyPassword keystoreProperties['keyPassword']
        storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
        storePassword keystoreProperties['storePassword']
    }
}
buildTypes {
    release {
        signingConfig signingConfigs.release
    }
}

}

flutter {
source ‘…/…’
}

dependencies {
implementation “org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version”
}

文档 https://docs.flutter.dev/deployment/android 提示用R8 这边没有用到混淆和压缩
这边Android版本是2020.3.1 Patch4
AndroidSDK 是Android11图片描述

页面打印接口信息报错
图片描述

写回答

3回答

CrazyCodeBoy

2022-01-06

应该没有网络请求权限导致的加下
    <uses-permission android:name="android.permission.INTERNET"/>
可参考下这块课程源码:https://git.imooc.com/coding-321/flutter_trip/src/master/android/app/src/main/AndroidManifest.xml#L8

0
0

CrazyCodeBoy

2022-01-05

其它接口能正常访问吗

0
1
慕尼黑3223685
都不行 包括我的那个web页面也报错了 net::ERR_CACHE_MISS
2022-01-05
共1条回复

CrazyCodeBoy

2022-01-04

界面上打印下接口返回,看接口有么有调用成功

0
1
慕尼黑3223685
接口报错 错误信息在问题最后
2022-01-04
共1条回复

Flutter从入门到进阶 实战携程网App 一网打尽核心技术

解锁Flutter开发新姿势,,系统掌握Flutter开发核心技术。

4788 学习 · 3270 问题

查看课程