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

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

问题描述

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

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

但是在最新的Android Studio中,没有jni/Android.mk.我将代码放在该网页的末尾吗?

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?

应该放在CMakeLists.txt中吗?还是应该在里面放些其他东西?

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

还是我只是制作一个Android.mk文件,如果是,那么在哪里(因为没有jni文件夹,只有cpp文件夹)?以及如何告诉Android Studio在哪里可以找到我的Android.mk文件?

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?

谢谢!

推荐答案

我已经完成了Gstreamer网站上的所有教程,但这非常困难.为了帮助其他人,我将其记录在案.这是 linux(ubuntu)的教程,但也可能在Windows上工作,如果对此有任何疑问,请问:)...我还将链接gitlab中的一个项目,准备在Android中运行Studio:
(教程5) https://gitlab.com/eduardoprado/gstreamer-tutorial5.git
(教程2) https://gitlab.com/eduardoprado/gstreamer-tutorial2.git

在Android Studio中使用库

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

了解GStreamer并将其集成到项目中的最佳方法是在此站点中进行教程: 对不起,您必须自己找到链接,我没有发布直接链接的声誉
但是,这些教程很旧,并且只能在Eclipse中使用,为了与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.使用Android Studio的导入"选项导入教程;
2.将Android Studio设置为使用NDK;
3.在"Android.mk"文件中设置一个变量;
4. Set Gradle仅编译某些体系结构;
5.将Gstreamer类复制到正确的路径.
6.从Android Studio禁用即时运行". (进行了编辑10/27/2017)
7.修复链接程序黄金参数"(仅适用于2017年11月28日的WINDOWS用户)

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.使用Android Studio的导入"选项导入教程

Android Studio可以选择从另一个IDE导入项目.要将针对Eclipse的Gstreamer项目导入以下步骤:
1.从git下载所有教程:;
2.在Android Studio中,转到文件"->新建导入项目";
3.在新的文件浏览器屏幕中,转到"gst-docs",选择所需的项目(在本例中为教程5)"android-tutorial-5",然后单击确定".



2.将Android Studio设置为使用NDK

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

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

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:

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

现在,外部构建文件将显示在项目的左侧标签中.还会出现一些错误,这是正常现象,将在下一部分中予以纠正.

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.在"Android.mk"文件中设置一个变量

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


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仅编译某些架构

发生上一节错误是因为Grade尝试针对不同的体系结构进行构建,但找不到要在MIPS中构建的文件.为解决此问题,我们将指定要构建的体系结构,但不包括MIPS:
1.在左侧浏览器选项卡中,展开Gradle脚本;
2.双击"build.gradle(模块:应用程序)"
3.在"moduleName"下的行中键入:
(以运行教程5)
-abiFilters'x86','armeabi','armeabi-v7a','arm64-v8a'
(运行教程2)
-abiFilters'x86','armeabi-v7a','arm64-v8a'
(edit 11/21/2017:最近我在使用arm64-v8a时遇到了问题...具有64位的设备不会显示实时流,我也解决了删除arm64-v8a"的问题)
(edit 3/29/2018:我意识到可能需要删除更多架构,具体取决于您的Gstreamer和NDK版本,如果不起作用,请尝试其他删除组合)


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.将Gstreamer类复制到正确的路径.

最后一个需要的配置与Main类中的包导入有关.


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


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

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

  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.从Android Studio禁用即时运行". (编辑于2017年10月27日)
尝试运行该项目时,Android Studio的此功能可能会导致问题,因此最好将其禁用.
禁用即时运行":

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

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.修复链接程序黄金参数"(仅Windows用户)

尝试使用Windows时,您将收到错误消息:
Error:error: invalid linker name in argument '-fuse-ld=gold'
要解决此问题,请执行以下操作:
1.转到 Android NDK链接器(GStreamer)-无效链接器名称-fuse-ld = gold
2.按照 Antoine Zambelli的回答说明进行操作.

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天全站免登陆