Android Studio 中的 Gstreamer 示例 [英] Gstreamer examples in Android Studio

查看:11
本文介绍了Android Studio 中的 Gstreamer 示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照他们的教程,我一直在尝试让 Gstreamer 在 Android Studio 中工作,例如,请参见此处:



<强> 2.将 Android Studio 设置为使用 NDK

现在项目已经导入,需要通知Android Studio该项目使用了NDK框架.因此,Gradle 将能够导入和处理所有依赖项.为此,我们需要链接文件 Android.mk(已经在教程文件夹中):
1. 右击左侧导航栏的应用"
2. 点击Link C++ Project with Gradle"
3. 在新窗口中:

  • 将构建系统"从CMake"更改为ndk-build"
  • 单击..."并浏览到 Android.mk 的位置/AndroidStudioProjects/android-studio-5/app/src/jni/Android.mk"
  • 点击确定

现在外部构建文件将出现在项目的左侧选项卡中.也会出现一些错误,属于正常现象,下节会更正.

3.在Android.mk"文件中设置一个变量

最后一节错误发生是因为Android.mk"找不到提取 GStreamer 的路径.因此,让我们将 GSTREAMER_ROOT_ANDROID 变量设置为提取 GStreamer 的路径.要实现这一点:
1. 浏览左侧选项卡并展开外部构建文件";
2.双击Android.mk打开文件;
3. 在第 10 行,在include $(BUILD_SHARED_LIBRARY)"下,输入:
- GSTREAMER_ROOT_ANDROID := 路径"
- 引号
- path 是提取 GStreamer 的路径(显然).
之后,Gradle 将同步并显示错误***Target arch ABI not supported: mips.Stop".


4.设置 Gradle 只编译一些架构

最后一个部分发生错误是因为 Grade 尝试为不同的架构构建,但在 MIPS 中找不到要构建的文件.为了解决这个问题,我们将指定要构建的架构,不包括 MIPS:
1. 在左侧浏览器选项卡中,展开 Gradle Scripts;
2.双击build.gradle(模块:app)"
3. 在moduleName"下的行中输入:
(运行教程5)
- abiFilters 'x86'、'armeabi'、'armeabi-v7a'、'arm64-v8a'
(运行教程 2)
- abiFilters 'x86'、'armeabi-v7a'、'arm64-v8a'
(编辑 2017 年 11 月 21 日:最近我遇到了 arm64-v8a 的问题...... 64 位设备不会显示直播,我也解决了删除 arm64-v8a")
(编辑 3/29/2018:我意识到可能需要根据您的 Gstreamer 和 NDK 版本删除更多架构,如果它不起作用,请尝试不同的删除组合)


5.将 Gstreamer 类复制到正确的路径.

最后需要的配置是关于 Main 类中的包导入.


出现上面显示的错误是因为没有 GStreamer 类来获取.init"函数.为了解决这个问题,我们需要从文件中复制 GStreamer 类并粘贴到指定的路径:

  1. 使用系统中的文件管理器浏览到您提取 GStreamer 的文件.
  2. 从提取的文件中,浏览到 GStreamer 类的位置.它位于/arm/share/gst-android/ndk-build/GStreamer.java复制 GStreamer.java
  3. 返回 Android Studio 并创建 Main 类尝试从左侧浏览器选项卡的/app/java 开始访问的导入路径.因此,对于上图,我们必须创建路径 org.freedesktop.gstreamer 并将文件 GStreamer.java 粘贴到其中:
  4. 右键java文件夹
  5. 新建-> 包
  6. 输入 org.freedesktop.gstreamer
  7. 右键单击 org.freedesktop.gstreamer 并粘贴5.导入错误现已解决,但新类有错误.要解决这些问题,您只需从复制的类中删除@"以及位于@"之间的所有内容.

6.从 Android Studio 禁用即时运行".(编辑于 2017 年 10 月 27 日)
Android Studio 中的此功能可能会在尝试运行项目时导致问题,因此最好禁用它.
禁用即时运行":

1. 在 Android Studio 中,转到文件"->设置..."(Ctrl+Alt+S)
2.构建、执行、部署"->即时运行"
3.取消选中启用即时运行以在部署时热交换代码/资源更改(默认启用)"
4. 点击应用"

7.修复链接器黄金参数"(仅限 WINDOWS 用户)

在尝试 Windows 时,您会收到错误消息:
错误:错误:参数 '-fuse-ld=gold' 中的链接器名称无效
修复它:
1. 转到 Android NDK Linker (GStreamer) - 无效链接器名称 -fuse-ld=gold
2. 按照 Antoine Zambelli 的回答说明进行操作.

I have been trying to get Gstreamer working in Android studio, following their tutorials, see for example here:

https://gstreamer.freedesktop.org/documentation/tutorials/android/link-against-gstreamer.html

But in the latest Android studio there is no jni/Android.mk. Where do I put the code at the end of that web page?

Should it go in the CMakeLists.txt? Or should something different go in there?

Or do I just make an Android.mk file, and if so, where (as there is no jni folder, only a cpp folder)? And how do I tell Android studio where to find my Android.mk file?

Thanks!

解决方案

I've made all tutorials from the Gstreamer's site work but it was very hard. To help another people I documented it. Here's the tutorial for linux (ubuntu) but might work on windows too, if you have any question regarding it, just ask :)... I will also link a project from gitlab ready to run in Android Studio:
(tutorial 5) https://gitlab.com/eduardoprado/gstreamer-tutorial5.git
(tutorial 2) https://gitlab.com/eduardoprado/gstreamer-tutorial2.git

Using the library at Android Studio

The best way to understand and integrate GStreamer into the project is doing the tutorials in this site: Sorry, you have to find the link by yourself, i don't have reputation to post the direct link
However these tutorials are old and were made to work in Eclipse, in order to work with Android Studio is necessary to:

1. Import the tutorials using Android Studio’s Import option;
2. Set the Android Studio to use NDK;
3. Set a variable inside the "Android.mk" file;
4. Set Gradle compile only some architecture;
5. Copy the Gstreamer class to the correct path.
6. Disable "Instante Run" from Android Studio. (edit made 10/27/2017)
7. Fix "linker gold argument" (edit made 11/28/2017 WINDOWS users only)

Each of these instructions will be explained in the following sections:

1. Import the tutorials using Android Studio’s Import option

Android Studio have an option to import project from another IDEs. To import the Gstreamer’s project made to Eclipse to the following steps:
1. Download all tutorials from git: ;
2. In Android Studio go to File -> New Import Project;
3. In the new browser for file screen, go to "gst-docs", select the desired project (in my case tutorial 5) "android-tutorial-5" and hit "OK".



2. Set the Android Studio to use NDK

Now that the project has been imported, it is needed to inform Android Studio that the project uses the NDK framework. Thus the Gradle will be able to import and handle all dependencies. To do this we need to link the file Android.mk (already in the tutorial folder):
1. Right click at "app" in the left navigation tab
2. Click at "Link C++ Project with Gradle"
3. In the new window:

  • Change "Build System" from "CMake" to "ndk-build"
  • Click at "..." and browse to the Android.mk’s location "/AndroidStudioProjects/android-studio-5/app/src/jni/Android.mk"
  • Hit OK

Now External Build Files will appear in the project’s left tab. Some erros will also appear, it is normal and will be corrected in the next sections.

3. Set a variable inside the "Android.mk" file

The last section error happens because "Android.mk" won’t find the path to where GStreamer was extracted. So let’s set the GSTREAMER_ROOT_ANDROID variable to the path where GStreamer was extracted. To achieve this:
1. Browse the left tab and expand "External Build FIles";
2. Double click at Android.mk to open the file;
3. At line 10, under "include $(BUILD_SHARED_LIBRARY)", type:
- "GSTREAMER_ROOT_ANDROID := path"
- NO quotation marks
- path is the path (obviously) where GStreamer was extracted.
After it Gradle will synchronize and an error "***Target arch ABI not supported: mips. Stop" will be showed.


4. Set Gradle compile only some architecture

The last section error occurs because Grade tries to build for different architectures but it doesn’t find the file to build in MIPS. To solve this problem we will specify the architectures to build excluding MIPS:
1. In the left browser tab, expand Gradle Scripts;
2. Double click at "build.gradle (Module: app)"
3. In the line under "moduleName" type :
(to run tutorial 5)
- abiFilters 'x86','armeabi', 'armeabi-v7a', 'arm64-v8a'
(to run tutorial 2)
- abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a'
(edit 11/21/2017: Recently I had problems with arm64-v8a... devices with 64 bits won't show live streaming, i solved "removing arm64-v8a" too )
(edit 3/29/2018: I realised that may be needed to remove more architecture depending of your Gstreamer and NDK version, if it's not working try different removal combinations)


5. Copy the Gstreamer class to the correct path.

The last needed configuration regards a package importation in the Main class.


The error showed above occurs because there’s no GStreamer class to get the ".init" function. To solve this we need to copy the class GStreamer from the file where it was extracted and paste at the specified path:

  1. Browse, using the file manager from your system, to the file where you extracted GStreamer.
  2. From the extracted file, browse to the location of GStreamer class. It is located at /arm/share/gst-android/ndk-build/GStreamer.java Copy GStreamer.java
  3. Go back to Android Studio and create the import path that the Main class is trying to access starting from /app/java at the left browser tab. So, to the image above, we have to create the path org.freedesktop.gstreamer and paste the file GStreamer.java in it:
  4. Right click at java Folder
  5. New-> Package
  6. Type org.freedesktop.gstreamer
  7. Right click at org.freedesktop.gstreamer and Paste 5.The importation error is now solved, but the new class has errors. To solve them all you have to do is erase from the copied class the "@" and all that’s located between the "@".

6. Disable "Instante Run" from Android Studio. (edit made 27/10/2017)
This feature from Android Studio could cause problems when trying to run the project, so it's a good idea disable it.
Disabling "Instante Run":

1. At Android Studio go to "File" -> "Settings..." (Ctrl+Alt+S)
2. "Build, Execution, Deployment" -> "Instant Run"
3. Uncheck "Enable Instant Run to hot swap code/resource changes on deploy (default enabled)"
4. Hit "Apply"

7. Fix "linker gold argument" (WINDOWS users only)

When trying to Windows you will get the error:
Error:error: invalid linker name in argument '-fuse-ld=gold'
To fix it:
1. Go to Android NDK Linker (GStreamer) - invalid linker name -fuse-ld=gold
2. Follow the Antoine Zambelli's answer instructions.

这篇关于Android Studio 中的 Gstreamer 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆