0

I have been trying to integrate/use OpenCV in Android Studio. But I keep getting stuck with this error.

C:\AndroidStudioProjects\IntegrateOpenCV341\app\src\main\res\values\colors.xml:1:1: Error: Content is not allowed in prolog.

I have tried to use:

  • OpenCV-2.4.9-Android-SDK

    reason: Most tutorials (outdated) work with this version

  • OpenCV-3.4.1-Android-SDK

    reason: Version with the latest tutorial (August 2018)

  • OpenCV-3.4.6-Android-SDK

    reason: Second latest version of OpenCV sdk android

  • OpenCV-4.1.0-Android-SDK

    reason: Latest version of OpenCV sdk android as of now

I went through these steps without error:

  1. Import Module (in a project)
  2. Add Dependency
  3. Edit compileSdkversion and targetSdkversion of OpenCV's build.gradle to match with app's build.gradle
  4. Made a Native folder (JNI folder) named jniLibs and copied the files inside sdk>native>libs to it
  5. Typed in this code in MainActivity.java to check if it works*

    package com.example.integrateopencv249; //also tried with 3.4.1 and 4.1.0
    
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.Toast;
    
    import org.opencv.android.OpenCVLoader;
    
    public class MainActivity extends AppCompatActivity {
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        if(OpenCVLoader.initDebug()) {
            Toast.makeText(getApplicationContext(), "OpenCV successfully loaded", Toast.LENGTH_SHORT).show();
        }
        else{
            Toast.makeText(getApplicationContext(), "OpenCV failed to load", Toast.LENGTH_SHORT).show();
        }
    }
    }
    

But after I run the last step. It just fails.

This is what is inside the color.xml (it is the same with all versions of OpenCV sdk)

package org.opencv.core;

import java.util.Arrays;import java.util.List;


public class MatOfRect extends Mat {// 32SC4private static final int _depth = CvType.CV_32S;private static final int

These are the details of my Android Studio:

Android Studio 3.3.2
Build #AI-182.5107.16.33.5314842, built on February 16, 2019
JRE: 1.8.0_152-release-1248-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
(All of the SDK Tools are installed)

I tried to search for solutions to this problem but none are helpful to my situation. Please help me :( I'm a complete beginner and I really want to start learning how to use OpenCV in Android Studio. I'd appreciate any help or suggestions.

note: I didn't continue OpenCV 4.1.0 after the first step because the module name only shows "java" and doesn't automatically update to the format "openCVLibrary410" as all the other versions before it do.

0

Errors are caused by unparsed code, not only in color.xml but to all of xml files. Solved by coding in the right contents in the right format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.