fix: 修复assets在example app中不能使用的问题 & 加入maven local的链接,修复flutter无法打包 aar的问题

This commit is contained in:
2025-09-10 17:33:26 +08:00
parent 4176116bb3
commit 62924296b2
13 changed files with 66 additions and 71 deletions

View File

@@ -4,7 +4,7 @@ version '1.0-SNAPSHOT'
buildscript { buildscript {
ext.kotlin_version = '2.1.20' ext.kotlin_version = '2.1.20'
repositories { repositories {
maven { url rootProject.file("../ai_chat_assistant/android/mavenLocal") } maven { url file("mavenLocal") }
google() google()
mavenCentral() mavenCentral()
@@ -18,7 +18,7 @@ buildscript {
allprojects { allprojects {
repositories { repositories {
maven { url rootProject.file("../ai_chat_assistant/android/mavenLocal") } maven { url file("mavenLocal") }
google() google()
mavenCentral() mavenCentral()
@@ -83,11 +83,11 @@ android {
} }
dependencies { dependencies {
// implementation 'com.alibaba.idst:nui-release:1.0.0' implementation 'com.alibaba.idst:nui-release:1.0.0'
// implementation 'com.alibaba:fastjson:1.2.83' implementation 'com.alibaba:fastjson:1.2.83'
// compileOnly files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar") // compileOnly files("$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar")
implementation(files("libs/fastjson-1.1.46.android.jar")) // implementation(files("libs/fastjson-1.1.46.android.jar"))
implementation(files("libs/nui-release-1.0.0.aar")) // implementation(files("libs/nui-release-1.0.0.aar"))
} }
} }

View File

@@ -1,26 +0,0 @@
allprojects {
repositories {
google()
mavenCentral()
maven { url = uri("https://maven.aliyun.com/repository/public/") }
maven { url = uri("https://maven.aliyun.com/repository/google/") }
maven { url = uri("https://maven.aliyun.com/repository/gradle-plugin/") }
maven { url = uri("https://storage.googleapis.com/download.flutter.io")}
}
}
val newBuildDir: Directory = rootProject.layout.buildDirectory.dir("../../build").get()
rootProject.layout.buildDirectory.value(newBuildDir)
subprojects {
val newSubprojectBuildDir: Directory = newBuildDir.dir(project.name)
project.layout.buildDirectory.value(newSubprojectBuildDir)
}
subprojects {
project.evaluationDependsOn(":app")
}
tasks.register<Delete>("clean") {
delete(rootProject.layout.buildDirectory)
}

View File

@@ -1,25 +0,0 @@
pluginManagement {
val flutterSdkPath = run {
val properties = java.util.Properties()
file("local.properties").inputStream().use { properties.load(it) }
val flutterSdkPath = properties.getProperty("flutter.sdk")
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
flutterSdkPath
}
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
id("com.android.application") version "8.7.3" apply false
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
}
include(":app")

View File

@@ -1,5 +1,11 @@
allprojects { allprojects {
repositories { repositories {
val mavenLocalPath = rootProject.file("../../android/mavenLocal")
println("Maven local path: ${mavenLocalPath.absolutePath}")
println("Maven local exists: ${mavenLocalPath.exists()}")
maven { url = uri(mavenLocalPath) }
maven { url = uri("https://maven.aliyun.com/repository/public") } maven { url = uri("https://maven.aliyun.com/repository/public") }
maven { url = uri("https://maven.aliyun.com/repository/google") } maven { url = uri("https://maven.aliyun.com/repository/google") }
maven { url = uri("https://maven.aliyun.com/repository/gradle-plugin") } maven { url = uri("https://maven.aliyun.com/repository/gradle-plugin") }

View File

@@ -28,7 +28,7 @@ class _MainScreenState extends State<MainScreen> {
Container( Container(
decoration: const BoxDecoration( decoration: const BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage('assets/images/bg.jpg'), image: AssetImage('assets/images/bg.jpg', package: 'ai_chat_assistant'),
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
), ),

View File

@@ -1,3 +1,4 @@
import 'package:ai_chat_assistant/utils/assets_util.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'dart:ui'; import 'dart:ui';
import '../widgets/chat_box.dart'; import '../widgets/chat_box.dart';
@@ -146,7 +147,8 @@ class _PartScreenState extends State<PartScreen> {
icon: Image.asset( icon: Image.asset(
'assets/images/open_in_full.png', 'assets/images/open_in_full.png',
width: 24, width: 24,
height: 24 height: 24,
package: 'ai_chat_assistant',
), ),
onPressed: _openFullScreen, onPressed: _openFullScreen,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,

View File

@@ -0,0 +1,31 @@
// assets_util.dart
import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';
/**
* AssetsUtil
* @description: 资源工具类
* @author guangfei.zhao
*/
class AssetsUtil {
static const String packageName = 'ai_chat_assistant';
static AssetImage getImage(String imageName) {
return AssetImage(
'assets/images/$imageName',
package: packageName,
);
}
static Widget getImageWidget(String imageName, {BoxFit? fit, double? width, double? height}) {
return Image.asset(
'assets/images/$imageName',
package: packageName,
fit: fit,
width: width,
height: height,
);
}
}

View File

@@ -18,6 +18,7 @@ class AssistantAvatar extends StatelessWidget {
child: Image.asset( child: Image.asset(
'assets/images/avatar.png', 'assets/images/avatar.png',
fit: BoxFit.contain, fit: BoxFit.contain,
package: 'ai_chat_assistant',
), ),
); );
} }

View File

@@ -123,7 +123,7 @@ class _ChatBubbleState extends State<ChatBubble> {
break; break;
case MessageStatus.completed: case MessageStatus.completed:
case MessageStatus.success: case MessageStatus.success:
icon = Image.asset('assets/images/checked.png', width: 20, height: 20); icon = Image.asset('assets/images/checked.png', width: 20, height: 20, package: 'ai_chat_assistant',);
color = Colors.white; color = Colors.white;
break; break;
case MessageStatus.failure: case MessageStatus.failure:
@@ -301,7 +301,7 @@ class _ChatBubbleState extends State<ChatBubble> {
}, },
child: Padding( child: Padding(
padding: const EdgeInsets.only(left: 12), padding: const EdgeInsets.only(left: 12),
child: Image.asset('assets/images/copy.png', child: Image.asset('assets/images/copy.png',package: 'ai_chat_assistant',
width: 22, height: 22), width: 22, height: 22),
), ),
), ),
@@ -315,9 +315,9 @@ class _ChatBubbleState extends State<ChatBubble> {
child: Padding( child: Padding(
padding: const EdgeInsets.only(left: 12), padding: const EdgeInsets.only(left: 12),
child: _liked child: _liked
? Image.asset('assets/images/liked2.png', ? Image.asset('assets/images/liked2.png',package: 'ai_chat_assistant',
width: 22, height: 22) width: 22, height: 22)
: Image.asset('assets/images/liked1.png', : Image.asset('assets/images/liked1.png',package: 'ai_chat_assistant',
width: 22, height: 22), width: 22, height: 22),
), ),
), ),
@@ -331,9 +331,9 @@ class _ChatBubbleState extends State<ChatBubble> {
child: Padding( child: Padding(
padding: const EdgeInsets.only(left: 12), padding: const EdgeInsets.only(left: 12),
child: _disliked child: _disliked
? Image.asset('assets/images/disliked2.png', ? Image.asset('assets/images/disliked2.png',package: 'ai_chat_assistant',
width: 22, height: 22) width: 22, height: 22)
: Image.asset('assets/images/disliked1.png', : Image.asset('assets/images/disliked1.png',package: 'ai_chat_assistant',
width: 22, height: 22)), width: 22, height: 22)),
), ),
], ],

View File

@@ -49,7 +49,7 @@ class _ChatFooterState extends State<ChatFooter>
child: GestureDetector( child: GestureDetector(
onTap: widget.onClear, onTap: widget.onClear,
child: Image.asset( child: Image.asset(
'assets/images/delete.png', 'assets/images/delete.png',package: 'ai_chat_assistant',
width: 24, width: 24,
height: 24, height: 24,
), ),
@@ -137,7 +137,7 @@ class _ChatFooterState extends State<ChatFooter>
child: GestureDetector( child: GestureDetector(
onTap: () {}, onTap: () {},
child: Image.asset( child: Image.asset(
'assets/images/keyboard_mini.png', 'assets/images/keyboard_mini.png',package: 'ai_chat_assistant',
width: 24, width: 24,
height: 24, height: 24,
), ),

View File

@@ -140,7 +140,7 @@ class _FloatingIconState extends State<FloatingIcon>
Intl.getCurrentLocale().startsWith('zh') Intl.getCurrentLocale().startsWith('zh')
? _iconImages[_imageIndex]:_iconImagesEn[_imageIndex], ? _iconImages[_imageIndex]:_iconImagesEn[_imageIndex],
width: iconSize, width: iconSize,
height: iconSize, height: iconSize,package: 'ai_chat_assistant',
), ),
); );
}, },

View File

@@ -1,3 +1,4 @@
import 'package:ai_chat_assistant/utils/assets_util.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'mini_audio_wave.dart'; import 'mini_audio_wave.dart';
@@ -36,6 +37,7 @@ class FloatingIconWithWave extends StatelessWidget {
width: iconSize, width: iconSize,
height: iconSize, height: iconSize,
fit: BoxFit.contain, fit: BoxFit.contain,
package: AssetsUtil.packageName
), ),
// 声波动画距离底部13px的位置 // 声波动画距离底部13px的位置
Positioned( Positioned(

View File

@@ -5,11 +5,14 @@ class RotatingImage extends StatefulWidget {
final double size; final double size;
final Duration duration; final Duration duration;
final String? package; // 添加这个参数
const RotatingImage({ const RotatingImage({
Key? key, Key? key,
required this.imagePath, required this.imagePath,
this.size = 20, this.size = 20,
this.duration = const Duration(seconds: 3) this.duration = const Duration(seconds: 3),
this.package = 'ai_chat_assistant', // 默认值
}) : super(key: key); }) : super(key: key);
@override @override
@@ -42,7 +45,8 @@ class _RotatingImageState extends State<RotatingImage>
child: Image.asset( child: Image.asset(
widget.imagePath, widget.imagePath,
width: widget.size, width: widget.size,
height: widget.size height: widget.size,
package: widget.package, // 使用传入的package参数
), ),
); );
} }