• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

AndroidManifest.xml not being unique in an app

I understand every application must have an AndroidManifest.xml file in its root directory that provides essential information about the app to the Android system, which the system must have before it can run any of the app's code.

When one writes a plug-in for other applications (such as Unity3D) to do something on an Android device, they usually end up having to place the 2 files called AndroidManifest.xml and classes.jar in Assets/Plugins/Android/libs of their Unity app, but what if you already have similar files in your "libs" folder?

For example, what if your Unity project already has "classes.jar" and "AndroidManifest.xml" due to other plug-ins being used in the app?

What do you do in this situation?
 
Well... I am sorry I am also a new learner of android studio, I wanna ask you a question that why and how we write plugins ? Can you guide me ?
I understand every application must have an AndroidManifest.xml file in its root directory that provides essential information about the app to the Android system, which the system must have before it can run any of the app's code.

When one writes a plug-in for other applications (such as Unity3D) to do something on an Android device, they usually end up having to place the 2 files called AndroidManifest.xml and classes.jar in Assets/Plugins/Android/libs of their Unity app, but what if you already have similar files in your "libs" folder?

For example, what if your Unity project already has "classes.jar" and "AndroidManifest.xml" due to other plug-ins being used in the app?

What do you do in this situation?
 
  • Like
Reactions: Joshua Martinez
Upvote 0
Well... I am sorry I am also a new learner of android studio, I wanna ask you a question that why and how we write plugins ? Can you guide me ?

I am new too, trying to learn just about enough to write a little plug-in for Unity3D to set the auto-focus on Android camera...

I found the following links useful:
https://docs.unity3d.com/Manual/AndroidJARPlugins.html
https://www.thepolyglotdeveloper.com/2014/06/creating-an-android-java-plugin-for-unity3d/

My goal is to achieve the suggestion in this post:
https://stackoverflow.com/questions/19076316/how-to-ask-webcam-to-auto-focus-with-unity3d
 
Upvote 0
I am new too, trying to learn just about enough to write a little plug-in for Unity3D to set the auto-focus on Android camera...

I found the following links useful:
https://docs.unity3d.com/Manual/AndroidJARPlugins.html
https://www.thepolyglotdeveloper.com/2014/06/creating-an-android-java-plugin-for-unity3d/

My goal is to achieve the suggestion in this post:
https://stackoverflow.com/questions/19076316/how-to-ask-webcam-to-auto-focus-with-unity3d
Okey You have written "but what if you already have similar files in your "libs" folder"
You mean that the files with same names in your libs folder already, right ?
If these are already there, try to re name your .jar and .xml file

I am just giving you idea on my programming mental base, just check it out, if it works, other wise we will think more on it :)
 
Last edited:
  • Like
Reactions: Joshua Martinez
Upvote 0
Okey You have written "but what if you already have similar files in your "libs" folder"
You mean that the files with same names in your libs folder already, right ?
If these are already there, try to re name your .jar and .xml file

I am just giving you idea on my programming mental base, just check it out, if it works, other wise we will think more on it :)

Actually, I just found something interesting in the link below...

Basically it says: Unity takes the main Android Manifest; finds all the Android Manifests of your plug-ins; merges them into the main Manifest using Google’s manifmerger class; and finally modifies this one main Manifest, automatically adding permissions, configuration options, features used, and other information to the Manifest.

https://docs.unity3d.com/Manual/android-manifest.html

I am just not sure if this all happens every time a new Manifest is added or whether we should 'trigger' this process...
 
  • Like
Reactions: Deleted User
Upvote 0
Actually, I just found something interesting in the link below...

Basically it says: Unity takes the main Android Manifest; finds all the Android Manifests of your plug-ins; merges them into the main Manifest using Google’s manifmerger class; and finally modifies this one main Manifest, automatically adding permissions, configuration options, features used, and other information to the Manifest.

https://docs.unity3d.com/Manual/android-manifest.html

I am just not sure if this all happens every time a new Manifest is added or whether we should 'trigger' this process...
Just try it and share the result :)
 
  • Like
Reactions: Joshua Martinez
Upvote 0
The app runs now and the error messages are gone from the logcat.

My C# code (Unity3D script) is basically this:

Code:
public class OcrAndroidFocus : MonoBehaviour
{
    /// Must be called after you have created your WebcamTexture.
    public static void Focus()
    {
        #if UNITY_ANDROID && !UNITY_EDITOR
        AndroidJavaObject androidJavaObject = new AndroidJavaObject("com.example.unityplugin.PlugInClass");
        androidJavaObject.CallStatic("EnableAutofocus");
        #endif
    }
}

which is called right after my WebCamTexture creation:

Code:
public void StartWebcam()
{
    if (!_isRunning)
    {
        _webCamTexture = new WebCamTexture();
        OcrAndroidFocus.Focus();  // Call the JAR file...
        gameObject.GetComponent<RawImage>().texture = _webCamTexture;
        _webCamTexture.Play();
        _isRunning = true;

        // Call only once on every webcam layout page.
        // _ocrScanner.ScanOcr();

        // Call the ScanOcr method every 2 seconds.
        StartCoroutine( ScanOcrAtIntervals(2f) );
    }
}

and of course the Java code in Android Studio:

Code:
package com.example.unityplugin;

import java.util.List;
import android.hardware.Camera;

public class PlugInClass
{
    public static void EnableAutofocus()
    {
        Camera camera = Camera.open();
        Camera.Parameters parameters = camera.getParameters();

        List<String> focusModes = parameters.getSupportedFocusModes();

        if ( focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO) )
        {
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
            System.out.println("camera focus set");
        }

        camera.setParameters(parameters);
    }
}

However, I do not see any improvement in focus, so I am guessing the camera does not focus because of this...

My next try will be switching the auto-focus with the following:

FOCUS_MODE_CONTINUOUS_VIDEO
FOCUS_MODE_CONTINUOUS_PICTURE
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones