【发布时间】:2019-12-20 08:02:48
【问题描述】:
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"
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.pwlp"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pwlp">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Partner Perks"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.apptreesoftware.barcodescan.BarcodeScannerActivity"/>
</application>
</manifest>
颤振中的条形码扫描仪:- 我已经为我的混合应用程序在颤振中集成了条形码扫描仪。 通过遵循这个 git 链接。 链接:-https://github.com/apptreesoftware/flutter_barcode_reader
一切顺利。我被安卓应用程序崩溃卡住了,
import 'package:flutter/material.dart';
import 'package:barcode_scan/barcode_scan.dart';
import 'package:flutter/services.dart';
import 'dart:async';
class Scanner extends StatefulWidget {
@override
_ScannerState createState() => _ScannerState();
}
class _ScannerState extends State<Scanner> {
String result = "Hey there !";
Future _scanQR() async {
try {
String qrResult = await BarcodeScanner.scan();
setState(() {
result = qrResult;
});
} on PlatformException catch (ex) {
if (ex.code == BarcodeScanner.CameraAccessDenied) {
setState(() {
result = "Camera permission was denied";
print(result);
});
} else {
setState(() {
result = "Unknown Error $ex";
print(result);
});
}
} on FormatException {
setState(() {
result = "You pressed the back button before scanning anything";
print(result);
});
} catch (ex) {
setState(() {
result = "Unknown Error $ex";
print(result);
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text(
result,
style: new TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),
),
),
floatingActionButton: FloatingActionButton.extended(
icon: Icon(Icons.camera_alt),
label: Text("Scan Now"),
onPressed: _scanQR,
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
}
}
我收到一个错误:-
android.content.ActivityNotFoundException:找不到明确的活动类 {com.example.pwlp/com.apptreesoftware.barcodescan.BarcodeScannerActivity};您是否在 AndroidManifest.xml 中声明了此活动?
任何建议或我已经做其他事情来解决。
请帮忙。 谢谢
【问题讨论】:
-
请分享您的 AndroidManifest.xml、您的项目级 build.gradle 和您的应用级 build.gradle
-
我在我的问题中添加了 AndroidManifest 代码,请检查并帮助我。
-
你忘了分享我提到的 gradle 文件。 AndroidManifest 看起来不错。
-
buildscript { ext.kotlin_version = '1.3.0' 存储库 { google() jcenter()} 依赖项 { classpath 'com.android.tools.build:gradle:3.3.2' classpath "org. jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }} allprojects { repositories { google() jcenter() }} rootProject.buildDir = '../build' 子项目 { project.buildDir = "${rootProject.buildDir} /${project.name}" } 子项目 { project.evaluationDependsOn(':app') } task clean(type: Delete) { delete rootProject.buildDir }
-
好的,这是您的项目级 build.gradle,现在请发布您的应用级 build.gradle
标签: android ios flutter hybrid-mobile-app barcode-scanner