Error: 无法找到符号 import org.opencv.BuildConfig; Android Studio

huangapple go评论67阅读模式
英文:

Error: Cannot find symbol import org.opencv.BuildConfig; Android studio

问题

I am trying to import openCV into Android Studio. 我试图将openCV导入Android Studio。
I am using 4.6 and Android Studio Flamingo | 2022.2.1 Patch 2 我使用4.6版本和Android Studio Flamingo | 2022.2.1 Patch 2。
I am getting the following error: 我遇到以下错误:
error: cannot find symbol 错误:找不到符号
import org.opencv.BuildConfig; 导入org.opencv.BuildConfig;
symbol: class BuildConfig 符号:类BuildConfig
location: package org.opencv 位置:包org.opencv

I am not sure how to fix this because I cannot find information on org.opencv.BuildConfig anywhere. 我不确定如何修复这个问题,因为我无法找到有关org.opencv.BuildConfig的信息。

Here is my build.gradle (:openCV) 这是我的build.gradle (:openCV)

plugins {
    id 'org.jetbrains.kotlin.android' version '1.7.10'
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

def openCVersionName = "4.6.0"
def openCVersionCode = ((4 * 100 + 6) * 100 + 0) * 10 + 0

println "OpenCV: " + openCVersionName + " " + project.buildscript.sourceFile

android {
    buildFeatures {
        aidl true
    }

    compileSdkVersion 33

    namespace 'org.opencv'

    defaultConfig {
        minSdkVersion 24
        targetSdkVersion 33

        versionCode openCVersionCode
        versionName openCVersionName

        externalNativeBuild {
            cmake {
                arguments "-DANDROID_STL=c++_shared"
                targets "opencv_jni_shared"
            }
        }
    }

    buildTypes {
        debug {
            packagingOptions {
                doNotStrip '**/*.so'  // controlled by OpenCV CMake scripts
            }
        }
        release {
            packagingOptions {
                doNotStrip '**/*.so'  // controlled by OpenCV CMake scripts
            }
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['native/libs']
            java.srcDirs = ['java/src']
            aidl.srcDirs = ['java/src']
            res.srcDirs = ['java/res']
            manifest.srcFile 'java/AndroidManifest.xml'
        }
    }

    externalNativeBuild {
        cmake {
            path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt')
        }
    }
}

dependencies {
}

I ran into a few issues. The first was that the package was defined in the AndroidManifest file of the openCV SDK which is now deprecated, so I defined namespace 'org.opencv' in the build.gradle (openCV). Then I had to set buildFeatures { aidl true } to true in build.gradle files for the app and openCV. That solved my other issues but now I do not know how to fix the BuildConfig issues. 我遇到了一些问题。首先,包在openCV SDK的AndroidManifest文件中定义,现在已经不推荐使用了,所以我在build.gradle (openCV)中定义了namespace 'org.opencv'。然后,我必须在应用程序和openCV的build.gradle文件中将buildFeatures { aidl true }设置为true。这解决了我的其他问题,但现在我不知道如何解决BuildConfig的问题。

英文:

I trying to import openCV into android studio. I am using 4.6 and Android Studio Flamingo | 2022.2.1 Patch 2 and I am getting following error:

error: cannot find symbol
import org.opencv.BuildConfig;
^
symbol: class BuildConfig
location: package org.opencv

I am not sure how to fix this because I cannot find information on org.opencv.BuildConfig anywhere.

Here is my build.gradle (:openCV)

plugins {
id 'org.jetbrains.kotlin.android' version '1.7.10'
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
def openCVersionName = "4.6.0"
def openCVersionCode = ((4 * 100 + 6) * 100 + 0) * 10 + 0
println "OpenCV: " +openCVersionName + " " + project.buildscript.sourceFile
android {
buildFeatures {
aidl true
}
compileSdkVersion 33
namespace 'org.opencv'
defaultConfig {
minSdkVersion 24
targetSdkVersion 33
versionCode openCVersionCode
versionName openCVersionName
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared"
targets "opencv_jni_shared"
}
}
}
buildTypes {
debug {
packagingOptions {
doNotStrip '**/*.so'  // controlled by OpenCV CMake scripts
}
}
release {
packagingOptions {
doNotStrip '**/*.so'  // controlled by OpenCV CMake scripts
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
main {
jniLibs.srcDirs = ['native/libs']
java.srcDirs = ['java/src']
aidl.srcDirs = ['java/src']
res.srcDirs = ['java/res']
manifest.srcFile 'java/AndroidManifest.xml'
}
}
externalNativeBuild {
cmake {
path (project.projectDir.toString() + '/libcxx_helper/CMakeLists.txt')
}
}
}
dependencies {
}

I ran into a few issues. The first was that the package was defined in the AndroidManifest file of the openCV SDK which is now deprecated so I defined namespace 'org.opencv' in the build.gradle (openCV). Then I had to set buildFeatures { aidl true } to true in build.gradle files for the app and openCV. That solved my other issues but now I do not know how to fix the BuildConfig issues.

答案1

得分: 2

我得到了相同的东西,并尝试在 org/opencv 中创建了一个 BuildConfig.java 文件,其中包含我在网上找到的代码:

package org.opencv;

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String LIBRARY_PACKAGE_NAME = "org.opencv";
  /**
   * @deprecated APPLICATION_ID is misleading in libraries. For the library package name use LIBRARY_PACKAGE_NAME
   */
  @Deprecated
  public static final String APPLICATION_ID = "org.opencv";
  public static final String BUILD_TYPE = "debug";
  public static final String FLAVOR = "";
  public static final int VERSION_CODE = 4100;
  public static final String VERSION_NAME = "4.1.0";
}

我将 VERSION_CODE 更改为 406000,将 VERSION_NAME 更改为 "4.6.0",它可以成功编译。这不是解决方案,但对我来说有效 Error: 无法找到符号 import org.opencv.BuildConfig; Android Studio

英文:

I got the same thing and tried to create a BuildConfig.java in org/opencv with code I found online:

package org.opencv;
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String LIBRARY_PACKAGE_NAME = "org.opencv";
/**
* @deprecated APPLICATION_ID is misleading in libraries. For the library package name use LIBRARY_PACKAGE_NAME
*/
@Deprecated
public static final String APPLICATION_ID = "org.opencv";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "";
public static final int VERSION_CODE = 4100;
public static final String VERSION_NAME = "4.1.0";
}

I changed VERSION_CODE to 406000 and VERSION_NAME to "4.6.0" and it compiles without problems.
This is not the solution but it works for me Error: 无法找到符号 import org.opencv.BuildConfig; Android Studio

答案2

得分: 0

打开Gradle的Scripts/gradle.properties(项目属性),并查找接近底部的行。
如果你发现下面的内容不存在,请添加它。

"android.defaults.buildfeatures.buildconfig=true"

然后"org.opencv.BuildConfig"将在构建时自动生成。

英文:

Open Gradle Scripts/gradle.properties (Project Properties) and look near the bottom line.
If you see the below is not there, add it.

"android.defaults.buildfeatures.buildconfig=true"

Then "org.opencv.BuildConfig" will be generated automatically at build time.

huangapple
  • 本文由 发表于 2023年5月31日 23:01:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76374886.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定