我正在使用
implementation ('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false }
implementation 'com.google.zxing:core:3.3.0'
所有的工作都很顺利。我可以构建已签名的 APK 并在 Android Studio 中运行它们。我可以在模拟器和真实设备上运行该项目,一切正常。
但是,我正在尝试在这个项目中设置 Fastlane,所以我需要运行 gradle assembleRelease
。这时候我就会收到标题错误。
Android 资源链接失败 /home/cescoferraro/go/src/github.com/onnidev/astaff/base/build/intermediates/merged_manifests/releaseFeature/AndroidManifest.xml:118:AAPT:错误:找不到资源样式/zxing_CaptureTheme(又名 live.onni.astaff.app:style/zxing_CaptureTheme)。
这是我如何启动扫描过程的方式,我正在使用自定义 Activity,以便在相机屏幕上设置闪光灯按钮。
override fun scan() {
IntentIntegrator(this@DashboardActivity)
.setCaptureActivity(QRCodeScannerActivity::class.java)
.setOrientationLocked(false)
.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE)
.initiateScan()
}
在清单文件中,我像这样声明活动:
<activity
android:name=".dashboard.QRCodeScannerActivity"
android:screenOrientation="portrait" />
如果我将zxing主题添加到活动中,我会看到错误两次。
<activity
android:theme="@style/zxing_CaptureTheme"
android:name=".dashboard.QRCodeScannerActivity"
android:screenOrientation="portrait" />
Android资源链接失败 /home/cescoferraro/go/src/github.com/onnidev/astaff/base/build/intermediates/merged_manifests/releaseFeature/AndroidManifest.xml:91: AAPT: 错误:找不到资源样式/zxing_CaptureTheme(又名live.onni.astaff.app:style/zxing_CaptureTheme)/home/cescoferraro/go/src/github.com/onnidev/astaff/base/build/intermediates/merged_manifests/releaseFeature/AndroidManifest.xml:119: AAPT: 错误:找不到资源样式/zxing_CaptureTheme(又名live.onni.astaff.app:style/zxing_CaptureTheme)
自定义活动扫描器代码如下:
class QRCodeScannerActivity:CaptureActivity(),DecoratedBarcodeView.TorchListener {
private var capture: CaptureManager? = null
private var barcodeScannerView: DecoratedBarcodeView? = null
private var switchFlashlightButton: Button? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_custom_scanner)
barcodeScannerView = findViewById<View>(R.id.zxing_barcode_scanner) as DecoratedBarcodeView
barcodeScannerView!!.setTorchListener(this)
switchFlashlightButton = findViewById<View>(R.id.switch_flashlight) as Button
if (!hasFlash()) {
switchFlashlightButton!!.visibility = View.GONE
}
capture = CaptureManager(this, barcodeScannerView!!)
capture!!.initializeFromIntent(intent, savedInstanceState)
capture!!.decode()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
val result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
Log.i(" whatever", result.contents)
}
override fun onResume() {
super.onResume()
capture!!.onResume()
}
override fun onPause() {
super.onPause()
capture!!.onPause()
}
override fun onDestroy() {
super.onDestroy()
capture!!.onDestroy()
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
this.capture!!.onSaveInstanceState(outState)
}
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
return barcodeScannerView!!.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event)
}
private fun hasFlash(): Boolean {
return applicationContext.packageManager
.hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)
}
fun switchFlashlight(view: View) {
println(view.alpha)
if (this.getString(R.string.turn_on_flashlight)!!.contentEquals(switchFlashlightButton!!.text)) {
barcodeScannerView!!.setTorchOn()
} else {
barcodeScannerView!!.setTorchOff()
}
}
override fun onTorchOn() {
switchFlashlightButton!!.setText(R.string.turn_off_flashlight)
}
override fun onTorchOff() {
switchFlashlightButton!!.setText(R.string.turn_on_flashlight)
}
}