在您的 gradle.properties 中,您可以看到 android.enableJetifier=true 当我们在 androidx 中迁移项目时处理所有第三方库,一个属性将处理所有迁移内容。
现在关于您的问题,我在开发 mp3 音频应用程序时使用了这两个类,但是在迁移到 Androidx 之后,它仍然没有添加任何额外的库。
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
我的课 :
package com.broadcast.audioplayerkotlin
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatSeekBar
import android.support.v4.media.session.MediaControllerCompat
import android.support.v4.media.MediaMetadataCompat
import android.widget.SeekBar
import android.support.v4.media.session.PlaybackStateCompat
import android.util.Log
class MediaSeekBar : AppCompatSeekBar {
private val TAG = "MediaSeekBar"
private var mMediaController: MediaControllerCompat? = null
private var mControllerCallback: ControllerCallback? = null
private var mIsTracking = false
private val mOnSeekBarChangeListener = object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {}
override fun onStartTrackingTouch(seekBar: SeekBar) {
mIsTracking = true
}
override fun onStopTrackingTouch(seekBar: SeekBar) {
mMediaController?.transportControls?.seekTo(progress.toLong())
mIsTracking = false
}
}
constructor(ctx: Context) : super(ctx)
constructor(code: Context, attrs: AttributeSet?) : super(code, attrs) {
super.setOnSeekBarChangeListener(mOnSeekBarChangeListener)
}
constructor(code: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(code, attrs) {
}
override fun setOnSeekBarChangeListener(l: SeekBar.OnSeekBarChangeListener) {
// Prohibit adding seek listeners to this subclass.
throw UnsupportedOperationException("Cannot add listeners to a MediaSeekBar")
}
fun setMediaController(mediaController: MediaControllerCompat?) {
if (mediaController != null) {
mControllerCallback = ControllerCallback()
mediaController.registerCallback(mControllerCallback!!)
} else if (mMediaController != null) {
mMediaController!!.unregisterCallback(mControllerCallback!!)
mControllerCallback = null
}
mMediaController = mediaController
}
fun disconnectController() {
if (mMediaController != null) {
mMediaController!!.unregisterCallback(mControllerCallback!!)
mControllerCallback = null
mMediaController = null
}
}
private inner class ControllerCallback : MediaControllerCompat.Callback() {
override fun onSessionDestroyed() {
super.onSessionDestroyed()
}
override fun onPlaybackStateChanged(state: PlaybackStateCompat?) {
super.onPlaybackStateChanged(state)
Log.d(TAG, "onPlaybackStateChanged: CALLED: playback state: " + state!!)
val progress = state?.position?.toInt() ?: 0
setProgress(progress)
}
override fun onMetadataChanged(metadata: MediaMetadataCompat?) {
super.onMetadataChanged(metadata)
}
}
}
摇篮依赖:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//RecyclerView
implementation 'com.android.support:recyclerview-v7:28.0.0'
def glideVersion = "4.8.0"
implementation "com.github.bumptech.glide:glide:$glideVersion"
annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
// ExoPlayer
implementation 'com.google.android.exoplayer:exoplayer:2.8.4' // 2.9.0 has min sdk 26
// Firestore
implementation 'com.google.firebase:firebase-firestore:17.1.2'
}
只是好奇为什么要添加额外的库。