質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

解決済

1回答

3754閲覧

【Android Studio】realmを使用する時の導入時記述で、jcenter~というエラーが出たので解決したい(現時点での正しい書き方を知りたい)

imatya999

総合スコア38

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2022/03/04 23:53

前提・実現したいこと

Android Studio(kotlin)でアプリのデータベースの使い方を勉強しようと思い、
realmというものを知ったので、導入しようと思った矢先・・・。

「参考にしているサイトや記事が、どれもちょっとずつ古い」ため、
ずっと何かしらエラーメッセージ的なものが出ているので困っています。
現時点での正しい書き方を知りたいです。
現時点で一番参考になったのはこちらの記事です。
https://teratail.com/questions/340534
(↑ただ質問者も「なぜか解決した」感じで根本的なところを把握していたかどうかは微妙な様子)

発生している問題・エラーメッセージ

jcenter maven repository is no longer receiving updates:newer library versions may be available elsewehre

該当のソースコード

▼build.gradel(:app)

kotlin

1plugins { 2 id 'com.android.application' 3 id 'org.jetbrains.kotlin.android' 4} 5 6apply plugin: 'com.android.application' 7apply plugin: 'kotlin-android' 8apply plugin: 'kotlin-android-extensions' 9apply plugin: 'kotlin-kapt' 10apply plugin: 'realm-android' 11 12android { 13 compileSdk 31 14 15 defaultConfig { 16 applicationId "com.example.samplerealm" 17 minSdk 21 18 targetSdk 31 19 versionCode 1 20 versionName "1.0" 21 22 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 23 } 24 25 buildTypes { 26 release { 27 minifyEnabled false 28 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 29 } 30 } 31 compileOptions { 32 sourceCompatibility JavaVersion.VERSION_1_8 33 targetCompatibility JavaVersion.VERSION_1_8 34 } 35 kotlinOptions { 36 jvmTarget = '1.8' 37 } 38} 39 40dependencies { 41 42 implementation 'androidx.core:core-ktx:1.7.0' 43 implementation 'androidx.appcompat:appcompat:1.4.1' 44 implementation 'com.google.android.material:material:1.5.0' 45 implementation 'androidx.constraintlayout:constraintlayout:2.1.3' 46 testImplementation 'junit:junit:4.13.2' 47 androidTestImplementation 'androidx.test.ext:junit:1.1.3' 48 androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 49}

▼build.gradle(project:)

kotlin

1// Top-level build file where you can add configuration options common to all sub-projects/modules. 2buildscript { 3 repositories { 4 jcenter() 5 } 6 dependencies { 7 classpath "io.realm:realm-gradle-plugin:10.8.0" 8 } 9} 10 11 12plugins { 13 id 'com.android.application' version '7.1.2' apply false 14 id 'com.android.library' version '7.1.2' apply false 15 id 'org.jetbrains.kotlin.android' version '1.6.10' apply false 16} 17 18task clean(type: Delete) { 19 delete rootProject.buildDir 20}

試したこと

色んなサイトを参考にしながら、ようやくここまでたどり着いた、という所で、
またしてもWarning・・・ということで、力尽きました。
●結局、今のところは合っているのか(jcenterの記述だけが違う)
●そもそも、今までのところが全部違うから何をやってもエラーなのか
自分では判断がつきません。
Realmの記述は、日に日に変化するようで、どのサイトも「ちょっとずつみなさん違う」というのも
素人には混乱の原因のようでして・・・。
現時点での正しい書き方をご教授願いたい

補足情報(FW/ツールのバージョンなど)

Android Studio Bumblebee

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

▼build.gradle(project:)
新規プロジェクト作成後の状態から、buildscript {~}の部分を追加

kotlin

1// Top-level build file where you can add configuration options common to all sub-projects/modules. 2buildscript { 3 dependencies { 4 classpath "io.realm:realm-gradle-plugin:10.8.0" 5 } 6} 7 8plugins { 9 id 'com.android.application' version '7.1.2' apply false 10 id 'com.android.library' version '7.1.2' apply false 11 id 'org.jetbrains.kotlin.android' version '1.5.30' apply false 12} 13 14task clean(type: Delete) { 15 delete rootProject.buildDir 16}

▼build.gradel(:app)
新規プロジェクト作成後の状態から、id 'kotlin-kapt'、id 'realm-android'を追加

kotlin

1plugins { 2 id 'com.android.application' 3 id 'org.jetbrains.kotlin.android' 4 id 'kotlin-kapt' 5 id 'realm-android' 6} 7 8android { 9 compileSdk 31 10 11 defaultConfig { 12 applicationId "com.example.myscheduler" 13 minSdk 23 14 targetSdk 31 15 versionCode 1 16 versionName "1.0" 17 18 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 19 } 20 21 buildTypes { 22 release { 23 minifyEnabled false 24 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 25 } 26 } 27 compileOptions { 28 sourceCompatibility JavaVersion.VERSION_1_8 29 targetCompatibility JavaVersion.VERSION_1_8 30 } 31 kotlinOptions { 32 jvmTarget = '1.8' 33 } 34 buildFeatures { 35 viewBinding true 36 } 37} 38 39dependencies { 40 41 implementation 'androidx.core:core-ktx:1.7.0' 42 implementation 'androidx.appcompat:appcompat:1.4.1' 43 implementation 'com.google.android.material:material:1.5.0' 44 implementation 'androidx.constraintlayout:constraintlayout:2.1.3' 45 implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1' 46 implementation 'androidx.navigation:navigation-ui-ktx:2.4.1' 47 testImplementation 'junit:junit:4.13.2' 48 androidTestImplementation 'androidx.test.ext:junit:1.1.3' 49 androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 50}

realmは10.4.0からjcenter()の代わりにmavenCentral()を使うようになりました。
jcenter自体が22年2月で閉鎖されているので、もはや記述は不要です。
realmリリースノート

build.gradel(:app) のplugins{} と apply plugin: は書き方の違いです。
plugins{} の方がより新しい書き方なので、こちらを使っていくのが良いかと思います。

投稿2022/03/12 15:33

ho-ta-te

総合スコア112

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問