【问题标题】:Adding opencv to android studio: Dependent features configured but no package ID was set将opencv添加到android studio:配置了依赖功能但未设置包ID
【发布时间】:2020-11-15 07:51:37
【问题描述】:

我正在尝试将 OpenCV 添加到我的 AndroidStudio 项目中。但是,在尝试构建项目时,出现上述错误:“已配置依赖功能,但未设置包 ID。”

我使用以下链接来实现:https://android.jlelse.eu/a-beginners-guide-to-setting-up-opencv-android-library-on-android-studio-19794e220f3c 我无法执行第 5 步,因为没有可供选择的选项。这只是一个空白屏幕。我假设,AndroidStudio 已经自动执行了该步骤。我可以像“Mat”一样从openCv访问对象,但是在构建项目时,我得到了上面提到的错误。

如果您需要更多信息,请告诉我。

【问题讨论】:

    标签: java android-studio opencv opencv4android


    【解决方案1】:

    您好,我也遇到了这个问题。 您提供的链接不适用于 opencv 版本 4.+.+。 我发现在 sdk 文件夹 (sdk/build.gradle) 内的 build.gradle 中有一个教程。 卸载您的 sdk 并尝试按照 sdk 文件夹中的最新教程进行操作。

    // This file is part of OpenCV project.
    // It is subject to the license terms in the LICENSE file found in the top-level directory
    // of this distribution and at http://opencv.org/license.html.
    
    //
    // Notes about integration OpenCV into existed Android Studio application project are below (application 'app' module should exist).
    //
    // This file is located in <OpenCV-android-sdk>/sdk directory (near 'etc', 'java', 'native' subdirectories)
    //
    // Add module into Android Studio application project:
    //
    // - Android Studio way:
    //   (will copy almost all OpenCV Android SDK into your project, ~200Mb)
    //
    //   Import module: Menu -> "File" -> "New" -> "Module" -> "Import Gradle project":
    //   Source directory: select this "sdk" directory
    //   Module name: ":opencv"
    //
    // - or attach library module from OpenCV Android SDK
    //   (without copying into application project directory, allow to share the same module between projects)
    //
    //   Edit "settings.gradle" and add these lines:
    //
    //   def opencvsdk='<path_to_opencv_android_sdk_rootdir>'
    //   // You can put declaration above into gradle.properties file instead (including file in HOME directory),
    //   // but without 'def' and apostrophe symbols ('): opencvsdk=<path_to_opencv_android_sdk_rootdir>
    //   include ':opencv'
    //   project(':opencv').projectDir = new File(opencvsdk + '/sdk')
    //
    //
    //
    // Add dependency into application module:
    //
    // - Android Studio way:
    //   "Open Module Settings" (F4) -> "Dependencies" tab
    //
    // - or add "project(':opencv')" dependency into app/build.gradle:
    //
    //   dependencies {
    //       implementation fileTree(dir: 'libs', include: ['*.jar'])
    //       ...
    //       implementation project(':opencv')
    //   }
    //
    //
    //
    // Load OpenCV native library before using:
    //
    // - avoid using of "OpenCVLoader.initAsync()" approach - it is deprecated
    //   It may load library with different version (from OpenCV Android Manager, which is installed separatelly on device)
    //
    // - use "System.loadLibrary("opencv_java4")" or "OpenCVLoader.initDebug()"
    

    【讨论】:

      【解决方案2】:

      我的项目也发生了这种情况,所以我在 java 文件中的 build.gradle 文件中做了一些更改。 你也可以试试这个 项目文件夹->java->build.gradle 文件

      打开这个文件并像这样编辑文件 - 应用插件:'com.android.library'

      android {
          compileSdkVersion 29
          buildToolsVersion "29.0.2"
      
          defaultConfig {
              //applicationId "org.opencv"
              minSdkVersion 16
              targetSdkVersion 29
          }
      
          buildTypes {
              release {
                  minifyEnabled false
                  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
              }
          }
      }
      

      试试这个也许对你有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-26
        • 1970-01-01
        • 1970-01-01
        • 2013-10-11
        • 2021-09-19
        相关资源
        最近更新 更多