Skip to content

Commit be9bdcb

Browse files
committed
Convert the project to androidx. (#436)
* Convert the project to androidx. Here are the steps I did for the conversion. Used Android Studio 3.2 canary 17 Auto conversion to androdx 1. Changed the targetSdkVersion and compileSdkVersion to 28 2. From Android Studio, navigated to "Refactor -> Refactor to AndroidX" Manual changes 1. Trimmed the leading package name (e.g. androidx.recyclerview.widget.RecyclerView -> RecyclerView in files where it's already imported) 2. Added "androidx.test:rules:1.1.0-alpha3" for a dependency (com.android.support.test:runner was there before the conversion, but some classes are now provided by a different dependency like "ActivityTestRule") 3. In build.gradle files, defined duplicate versions through variables. (e.g. 1.0.0-alpha3 for the androidxCoreVersion) 4. Handled API changes - LayoutManager.getChildAt is now nullable 5. Optimized import order These issues need be addressed by the conversion tool. I'll file these as issues. 1. double quotations were replaced by single quotations in the dependencies in build.gradle. It's going to be an issue if the versions are defined through variables. 2. Unneeded leading package names. e.g. val navigationView: com.google.android.material.navigation.NavigationView = findViewById(R.id.nav_view) Should be val navigationView: NavigationView = findViewById(R.id.nav_view) 3. Add a missing dependency automatically? Like androidx.test.rules.
1 parent 80cd42e commit be9bdcb

File tree

54 files changed

+536
-451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+536
-451
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jobs:
33
build:
44
working_directory: ~/code
55
docker:
6-
- image: circleci/android:api-27-alpha
6+
- image: circleci/android:api-28-alpha
77
environment:
88
JVM_OPTS: -Xmx3200m
99
MAX_RETRY: 4

build.gradle

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,27 @@
1919
buildscript {
2020
ext {
2121
minSdkVersion = 14
22-
targetSdkVersion = 27
23-
compileSdkVersion = 27
22+
targetSdkVersion = 28
23+
compileSdkVersion = 28
24+
2425
androidGradlePluginVersion = "3.1.3"
2526
androidMavenGradlePluginVersion = "1.5"
27+
androidxCoreVersion = "1.0.0-alpha3"
28+
androidxEspressoVersion = "3.1.0-alpha3"
29+
androidxTestVersion = "1.1.0-alpha3"
30+
junitVersion = "4.12"
2631
gradleBintrayPluginVersion = "1.6"
27-
kotlinVersion = "1.2.30"
28-
supportLibVersion = "27.1.0"
29-
espressoVersion = "3.0.0"
32+
kotlinVersion = "1.2.41"
33+
materialVersion = "1.0.0-alpha3"
3034
testRunnerVersion = "1.0.0"
31-
junitVersion = "4.12"
3235
}
3336

3437
repositories {
3538
jcenter()
3639
google()
3740
}
3841
dependencies {
39-
classpath "com.android.tools.build:gradle:$androidGradlePluginVersion"
42+
classpath "com.android.tools.build:gradle:3.2.0-alpha17"
4043
classpath "com.github.dcendents:android-maven-gradle-plugin:$androidMavenGradlePluginVersion"
4144
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradleBintrayPluginVersion"
4245
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

demo-cat-gallery/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ android {
2727
versionCode 1
2828
versionName "1.0"
2929

30-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
30+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3131
}
3232
buildTypes {
3333
release {
@@ -40,8 +40,8 @@ android {
4040

4141
dependencies {
4242
implementation project(path: ":flexbox")
43-
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
44-
implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
45-
implementation "com.android.support:recyclerview-v7:${rootProject.ext.supportLibVersion}"
46-
implementation "org.jetbrains.kotlin:kotlin-stdlib:${rootProject.ext.kotlinVersion}"
43+
implementation "androidx.appcompat:appcompat:${rootProject.androidxCoreVersion}"
44+
implementation "androidx.recyclerview:recyclerview:${rootProject.androidxCoreVersion}"
45+
implementation "com.google.android.material:material:${rootProject.materialVersion}"
46+
implementation "org.jetbrains.kotlin:kotlin-stdlib:${rootProject.kotlinVersion}"
4747
}

demo-cat-gallery/src/main/java/com/google/android/flexbox/apps/catgallery/CatAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package com.google.android.flexbox.apps.catgallery
1818

19-
import android.support.v7.widget.RecyclerView
2019
import android.view.LayoutInflater
2120
import android.view.ViewGroup
21+
import androidx.recyclerview.widget.RecyclerView
2222

2323
/**
2424
* Adapter class that handles the data set with the {@link RecyclerView.LayoutManager}

demo-cat-gallery/src/main/java/com/google/android/flexbox/apps/catgallery/CatViewHolder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
package com.google.android.flexbox.apps.catgallery
1818

19-
import android.support.annotation.DrawableRes
20-
import android.support.v7.widget.RecyclerView
2119
import android.view.View
2220
import android.widget.ImageView
21+
import androidx.annotation.DrawableRes
22+
import androidx.recyclerview.widget.RecyclerView
2323
import com.google.android.flexbox.FlexboxLayoutManager
2424

2525
/**

demo-cat-gallery/src/main/java/com/google/android/flexbox/apps/catgallery/MainActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
package com.google.android.flexbox.apps.catgallery
1818

1919
import android.os.Bundle
20-
import android.support.v7.app.AppCompatActivity
21-
import android.support.v7.widget.RecyclerView
22-
import android.support.v7.widget.Toolbar
20+
import androidx.appcompat.app.AppCompatActivity
21+
import androidx.appcompat.widget.Toolbar
22+
import androidx.recyclerview.widget.RecyclerView
2323
import com.google.android.flexbox.AlignItems
2424
import com.google.android.flexbox.FlexDirection
2525
import com.google.android.flexbox.FlexWrap

demo-cat-gallery/src/main/res/layout/activity_main.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
16-
<android.support.design.widget.CoordinatorLayout
16+
<androidx.coordinatorlayout.widget.CoordinatorLayout
1717
xmlns:android="http://schemas.android.com/apk/res/android"
1818
xmlns:app="http://schemas.android.com/apk/res-auto"
1919
xmlns:tools="http://schemas.android.com/tools"
@@ -23,31 +23,31 @@ limitations under the License.
2323
android:fitsSystemWindows="true"
2424
tools:context="com.google.android.flexbox.apps.catgallery.MainActivity">
2525

26-
<android.support.design.widget.AppBarLayout
26+
<com.google.android.material.appbar.AppBarLayout
2727
android:id="@+id/app_bar"
2828
android:layout_width="match_parent"
2929
android:layout_height="@dimen/app_bar_height"
3030
android:fitsSystemWindows="true"
3131
android:theme="@style/AppTheme.AppBarOverlay">
3232

33-
<android.support.design.widget.CollapsingToolbarLayout
33+
<com.google.android.material.appbar.CollapsingToolbarLayout
3434
android:id="@+id/toolbar_layout"
3535
android:layout_width="match_parent"
3636
android:layout_height="match_parent"
3737
android:fitsSystemWindows="true"
3838
app:contentScrim="?attr/colorPrimary"
3939
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
4040

41-
<android.support.v7.widget.Toolbar
41+
<androidx.appcompat.widget.Toolbar
4242
android:id="@+id/toolbar"
4343
android:layout_width="match_parent"
4444
android:layout_height="?attr/actionBarSize"
4545
app:layout_collapseMode="pin"
4646
app:popupTheme="@style/AppTheme.PopupOverlay"/>
4747

48-
</android.support.design.widget.CollapsingToolbarLayout>
49-
</android.support.design.widget.AppBarLayout>
48+
</com.google.android.material.appbar.CollapsingToolbarLayout>
49+
</com.google.android.material.appbar.AppBarLayout>
5050

5151
<include layout="@layout/content_main"/>
5252

53-
</android.support.design.widget.CoordinatorLayout>
53+
</androidx.coordinatorlayout.widget.CoordinatorLayout>

demo-cat-gallery/src/main/res/layout/content_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
16-
<android.support.v7.widget.RecyclerView
16+
<androidx.recyclerview.widget.RecyclerView
1717
xmlns:app="http://schemas.android.com/apk/res-auto"
1818
xmlns:android="http://schemas.android.com/apk/res/android"
1919
app:layout_behavior="@string/appbar_scrolling_view_behavior"

demo-playground/build.gradle

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ android {
2727
versionCode 1
2828
versionName "1.0"
2929

30-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
30+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3131
}
3232
buildTypes {
3333
release {
@@ -40,16 +40,17 @@ android {
4040

4141
dependencies {
4242
implementation project(":flexbox")
43-
implementation "com.android.support:support-v4:${rootProject.ext.supportLibVersion}"
44-
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
45-
implementation "com.android.support:preference-v7:${rootProject.ext.supportLibVersion}"
46-
implementation "com.android.support:preference-v14:${rootProject.ext.supportLibVersion}"
47-
implementation "com.android.support:design:${rootProject.ext.supportLibVersion}"
43+
implementation "androidx.legacy:legacy-support-v4:${rootProject.androidxCoreVersion}"
44+
implementation "androidx.appcompat:appcompat:${rootProject.androidxCoreVersion}"
45+
implementation "androidx.preference:preference:${rootProject.androidxCoreVersion}"
46+
implementation "androidx.legacy:legacy-preference-v14:${rootProject.androidxCoreVersion}"
47+
implementation "com.google.android.material:material:${rootProject.materialVersion}"
4848
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
4949

5050
testImplementation "junit:junit:${rootProject.ext.junitVersion}"
5151

52-
androidTestImplementation "com.android.support:support-annotations:${rootProject.ext.supportLibVersion}"
53-
androidTestImplementation "com.android.support.test:runner:${rootProject.ext.testRunnerVersion}"
54-
androidTestImplementation "com.android.support.test.espresso:espresso-core:${rootProject.ext.espressoVersion}"
52+
androidTestImplementation "androidx.annotation:annotation:${rootProject.androidxCoreVersion}"
53+
androidTestImplementation "androidx.test:runner:${rootProject.androidxTestVersion}"
54+
androidTestImplementation "androidx.test:rules:${rootProject.androidxTestVersion}"
55+
androidTestImplementation "androidx.test.espresso:espresso-core:${rootProject.androidxEspressoVersion}"
5556
}

demo-playground/src/androidTest/java/com/google/android/apps/flexbox/test/MainActivityTest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@
1717
package com.google.android.apps.flexbox.test
1818

1919
import android.content.pm.ActivityInfo
20-
import android.support.design.widget.NavigationView
21-
import android.support.test.InstrumentationRegistry
22-
import android.support.test.espresso.Espresso.onView
23-
import android.support.test.espresso.action.ViewActions.*
24-
import android.support.test.espresso.matcher.ViewMatchers.withId
25-
import android.support.test.filters.FlakyTest
26-
import android.support.test.filters.MediumTest
27-
import android.support.test.rule.ActivityTestRule
28-
import android.support.test.runner.AndroidJUnit4
2920
import android.view.View
3021
import android.widget.ArrayAdapter
3122
import android.widget.RadioGroup
3223
import android.widget.Spinner
3324
import android.widget.TextView
25+
import androidx.test.InstrumentationRegistry
26+
import androidx.test.espresso.Espresso.onView
27+
import androidx.test.espresso.action.ViewActions.*
28+
import androidx.test.espresso.matcher.ViewMatchers.withId
29+
import androidx.test.filters.FlakyTest
30+
import androidx.test.filters.MediumTest
31+
import androidx.test.rule.ActivityTestRule
32+
import androidx.test.runner.AndroidJUnit4
3433
import com.google.android.apps.flexbox.R
3534
import com.google.android.flexbox.*
35+
import com.google.android.material.navigation.NavigationView
3636
import junit.framework.Assert.*
3737
import org.hamcrest.MatcherAssert.assertThat
3838
import org.hamcrest.core.Is.`is`

0 commit comments

Comments
 (0)