【问题标题】:AAPT: error: resource style/zxing_CaptureTheme (aka.....app:style/zxing_CaptureTheme) not foundAAPT:错误:找不到资源样式/zxing_CaptureTheme(又名.....应用程序:样式/zxing_CaptureTheme)
【发布时间】:2019-02-21 22:43:56
【问题描述】:

我正在使用

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) 未找到。

这就是我开始扫描过程的方式,我正在使用 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/releaseFeature/AndroidManifest.xml:91: AAPT: error: resource style/zxing_CaptureTheme (aka 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) 未找到。

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

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

}

【问题讨论】:

  • 这里有同样的问题。你找到解决办法了吗?

标签: android kotlin qr-code barcode-scanner aapt


【解决方案1】:

你可以在repo 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:

这为我解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-21
    • 1970-01-01
    • 2022-10-18
    • 2020-08-27
    • 2019-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多