AAPT错误:找不到资源样式/ zxing_CaptureTheme(又名.....app:style/zxing_CaptureTheme)

4

我正在使用

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)
}

}


这里也有同样的问题。你找到解决方案了吗? - Jan Feyen
2个回答

2

您可以在存储库zxing-android-embedded/zxing-android-embedded中找到缺失的样式

<?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中:

enter image description here

这对我很有帮助。

0

你可以通过访问flutter文档并在文件android/app/main/res/value中添加以下行来轻松解决此问题:

删除旧值并添加在文档中找到的新值。

以及文件:android/app/main/res/value-night

删除旧值并添加在文档中找到的新值。

你可以通过文档查看代码。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接