AAPT: error: resource style/zxing_CaptureTheme (aka.....app:style/zxing_CaptureTheme) not found

Viewed 1457

I am using

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

I all works just fine. I can build signed APK and run them from within Android Studio. I can run the project both on a emulator and on a real device. things just work.

But I am trying to setup Fastlane on this project, so I need to run gradle assembleRelease. Thats when I get the title error.

Android resource linking failed /home/cescoferraro/go/src/github.com/onnidev/astaff/base/build/intermediates/merged_manifests/releaseFeature/AndroidManifest.xml:118: AAPT: error: resource style/zxing_CaptureTheme (aka live.onni.astaff.app:style/zxing_CaptureTheme) not found.

this is how i am starting the scan process, I am using a customActivity so i can setup a flash button on the camera screen

override fun scan() {
    IntentIntegrator(this@DashboardActivity)
            .setCaptureActivity(QRCodeScannerActivity::class.java)
            .setOrientationLocked(false)
            .setDesiredBarcodeFormats(IntentIntegrator.QR_CODE)
            .initiateScan()
}

on the manifest I declare the activiy like this

    <activity
        android:name=".dashboard.QRCodeScannerActivity"
        android:screenOrientation="portrait" />

if I happen to add the zxing theme to the activiy. I get to see to error twice

    <activity
        android:theme="@style/zxing_CaptureTheme"
        android:name=".dashboard.QRCodeScannerActivity"
        android:screenOrientation="portrait" />

Android resource linking failed /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) not found. /home/cescoferraro/go/src/github.com/onnidev/astaff/base/build/intermediates/merged_manifests/releaseFeature/AndroidManifest.xml:119: AAPT: error: resource style/zxing_CaptureTheme (aka live.onni.astaff.app:style/zxing_CaptureTheme) not found.

the custom activity scanner code looks like this

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

}

1 Answers

You can find the missing style in the 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>

I've added the style manually to the existing file base/res/values/styles.xml:

enter image description here

This resolved it for me.

Related