当前位置: 首页 > 知识库问答 >
问题:

错误:资源样式/zxing_CaptureTheme(又名......

狄峻熙
2023-03-14

我正在使用

implementation ('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false }
implementation 'com.google.zxing:core:3.3.0'

我都工作得很好。我可以构建签名APK并在Android Studio中运行它们。我可以在模拟器和真实设备上运行该项目。事情就是这样。

但是我正在尝试在这个项目上设置Fastlane,所以我需要运行gradle assembleReleas。这就是我得到标题错误的时候。

Android资源链接失败/home/cescoferraro/go/src/github.com/onnidev/astaff/base/build/intermediates/merged_manifests/releaseffeature/AndroidManifest。xml:118:AAPT:error:resource style/zxing\u capturateme(又名live.onni.astaff.app:style/zxing\u capturateme)未找到。

这就是我开始扫描过程的方式,我使用customActivity,这样我可以在相机屏幕上设置一个闪光灯按钮

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/releaseffeature/AndroidManifest。xml:91:AAPT:error:resource style/zxing\u capturateme(又名live.onni.astaff.app:style/zxing\u capturateme)未找到/home/cescoferraro/go/src/github.com/onnidev/astaff/base/build/intermediates/merged_manifests/releaseffeature/AndroidManifest。xml:119:AAPT:error:resource style/zxing\u capturateme(又名live.onni.astaff.app:style/zxing\u capturateme)未找到。

自定义活动扫描程序代码如下所示

类QRCodeScanneractive:Capture Active(),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)
}

}

共有1个答案

赫连明诚
2023-03-14

您可以在repo zxing-android-嵌入/zxing-android-嵌入中找到缺少的样式

<?xml version="1.0" encoding="UTF-8"?>
<resources>
  <style name="zxing_CaptureTheme" parent="android:Theme.Holo.NoActionBar.Fullscreen">
  </style>
</resources>

我已将样式手动添加到现有文件base/res/values/styles.xml中:

这为我解决了问题。

 类似资料: