首页 > 解决方案 > 为什么当我删除 @SuppressLint("RestrictedApi") 时,Android Studio 会显示“只能从同一个库组中调用”?

问题描述

代码 A来自CameraX项目,您可以查看源代码

当我删除时,Android Studio 会显示“只能从同一个库组调用” @SuppressLint("RestrictedApi"),你可以看到图 1

为什么我不能 @SuppressLint("RestrictedApi")Code A中删除?deos 限制 API 是什么意思?

代码 A

@SuppressLint("RestrictedApi")
    private fun updateCameraUi() {
        ...

        // Listener for button used to switch cameras
        controls.findViewById<ImageButton>(R.id.camera_switch_button).setOnClickListener {
            lensFacing = if (CameraX.LensFacing.FRONT == lensFacing) {
                CameraX.LensFacing.BACK
            } else {
                CameraX.LensFacing.FRONT
            }
            try {
                // Only bind use cases if we can query a camera with this orientation
                CameraX.getCameraWithLensFacing(lensFacing)

                // Unbind all use cases and bind them again with the new lens facing configuration
                CameraX.unbindAll()
                bindCameraUseCases()
            } catch (exc: Exception) {
                // Do nothing
            }
        }
    }

图 1

在此处输入图像描述

标签: androidandroid-studio

解决方案


自本教程制作以来,库中发生了重大变化。与教程相同,
将包版本恢复为,即可解决问题。1.0.0-alpha06


推荐阅读