android studio整合ijkplayer

來源:互聯網
上載者:User

標籤:pre   轉換   col   pen   .so檔案   那是   下載sdk   ann   false   

介紹

ijkplayer是一款非常火的開源視頻播放器,android和IOS通用。關於怎麼編譯怎麼匯入android Studio中自己的項目,其中坑很多,本篇記錄下自己的操作記錄。ijkplayer現在的版本是0.8.3,當然是使用最新的版本整合了。

編譯ijkplayer

關於編譯,我是在Ubuntu上編譯後拷貝到win10中的,ijkplayer源碼需要gcc編譯,windows各種不好用,如果使用cynwin還不如在ubuntu下編譯。

編譯的過程是下載sdk,ndk。設定環境變數後按照github上的說明編譯即可,具體可參考這篇文章.

android studio整合ijkplayer

1.匯入到你的項目中

android studio開啟你的項目,File->Import Module...選擇ijkplayer的anroid/ijkplayer目錄,ijk-example依賴所有庫,所以匯入後所有項目都會匯入到你的項目中。

2.將android/ijkplayer目錄下的tools檔案夾也拷貝到自己項目的根目錄下。

3. 在ijkplayer-java\src\main\目錄下建立一個名為jniLibs的檔案夾,將各個ijkplayer-xxx目錄中的\src\main\libs目錄下的檔案夾拷貝到jniLibs檔案夾中,如:ijkplayer--armv7a的該目錄下包含armeabi-v7a這個檔案夾,其中包含了該平台對應的.so檔案,如果希望包含所有平台的,就將所有ijkplayer-xxx下的全部拷過來,如果只希望某幾個平台的,就只拷貝它們的。

4.將ijkplayer-xxx的目錄全部從項目中刪除掉,只保留ijkplayer-example、ijkplayer-java、ijkplayer-exo以及tools檔案夾,其中ijkplayer-example依賴於後面幾個。android studio刪除項目需如所示:

並將相對應的檔案夾刪除即可。

5.將ijkplayer-example修改為Module的形式,因為ijkplayer-example本身是一個application工程,預設不產生aar檔案,且裡面的資源互相依賴,難以像舊版本通過複製所需的幾個java檔案到自己工程中的方式來使用,所以不如將整個ijkplayer-example轉換為我們工程的一個Module。具體方法是:

先修改ijkplayer-example目錄下的build.gradle檔案,如下:

apply plugin: ‘com.android.library‘android {    // http://tools.android.com/tech-docs/new-build-system/tips    //noinspection GroovyAssignabilityCheck    compileSdkVersion rootProject.ext.compileSdkVersion    //noinspection GroovyAssignabilityCheck    buildToolsVersion rootProject.ext.buildToolsVersion    lintOptions {        abortOnError false    }    defaultConfig {        minSdkVersion 9        targetSdkVersion rootProject.ext.targetSdkVersion        versionCode rootProject.ext.versionCode        versionName rootProject.ext.versionName    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘        }    }    buildToolsVersion ‘25.0.0‘}dependencies {    compile fileTree(include: [‘*.jar‘], dir: ‘libs‘)    compile ‘com.android.support:appcompat-v7:25.0.0‘    compile ‘com.android.support:preference-v7:23.0.1‘    compile ‘com.android.support:support-annotations:23.0.1‘    compile ‘com.squareup:otto:1.3.8‘    compile project(‘:ijkplayer-java‘)    compile project(‘:ijkplayer-exo‘)}

  注意:

  • apply plugin: ‘com.android.application‘要改為apply plugin: ‘com.android.library‘
  • applicationId "tv.danmaku.ijk.media.example"這句要去掉
  • compile ‘com.android.support:appcompat-v7:25.0.0‘

   compile ‘com.android.support:preference-v7:23.0.1‘

   compile ‘com.android.support:support-annotations:23.0.1‘

   compile ‘com.squareup:otto:1.3.8‘

   這幾個修改為自己安裝的版本。

6.在ijkplayer-example根目錄下增加一個gradle.properties檔案,內容如下:

POM_NAME=ijkplayer-examplePOM_ARTIFACT_ID=ijkplayer-examplePOM_PACKAGING=aar

7.在自己的項目中添加依賴項,如所示:

 

完成上述操作,點擊async gradle即可。

其他錯誤:

如果出現

Error:(3) Error retrieving parent for item: No resource found that matches the given name ‘android:TextAppearance.Material.Widget.Button.Borderless.Colored‘.

如上類似錯誤,那是幾個項目的sdk版本不同引起的,四個項目包含你自己的項目的compileSdkVersion 、

buildToolsVersion、targetSdkVersion和compile ‘com.android.support:appcompat-v7:25.0.0‘
幾個版本必須要統一,如果不統一會出現各種問題。

android studio整合ijkplayer

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.