Search result for Question Taged kotlin
There are some results of your Tag: kotlin
    How to deal with deprecated gradle features were used in this build, making it incompatible with gradle 8.0

    1. FAILURE
    2. Sometime when you try to build the app you may encounter this FAILURE.
      ..."Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0."
      

    3. Most common Solution
    4. Run the Gradle build with a command line argument --warning-mode=all to see what exactly the deprecated features are.

      It will give you a detailed description of found issues with links to the Gradle docs for instructions how to fix your build.

      Adding --stacktrace to that, you will also be able to pinpoint where the warning comes from, if it's triggered by outdated code in one of the plugins and not your build script.

    5. Solution 2
    6. if the abouve Solution dont work Try this one

      cd android && ./gradlew clean && ./gradlew :app:bundleRelease
      

    7. Solution 3
    8. The process below worked in many case- First check Gradle Version:

      cd android
      ./gradlew -v
      

      In my case it was 6.5

      Go to https://developer.android.com/studio/releases/gradle-plugin and you'll get the plugin version for your gradle version. For gradle version 6.5, the plugin version is 4.1.0

      Then go to app/build.gradle and change classpath 'com.android.tools.build:gradle:<plugin_version>

    9. Solution 4
    10. if your project is incompatible with Gradle 8.0 .Here's what worked for you: First write this line of code in the Android Studio terminal:

      ./gradlew build --warning-mode all
      

      When you do that, you will be shown in the logcat what is found to be deprecated or an issue in your project, for me it was the jcenter() repository that needed to be removed in my settings.gradle file and also I needed to update classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21" to classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30" in my build.gradle project file.

      Once I did these things, my project built perfectly and installed on my emulator

    Kyle Elkins 2022-08-09
    build android apps from nodejs

    If You Can Build A Website, You Can Build An Android App!
    Android.js simple takes your node.js website and puts it into a WebView.

    Yeah, i know that's a lot of disadvantages there but it also provides different APIs for you to interact with.

    an android.js application isn't only a WebView like a front end of a site, it can also interact with the backend and interact with files and much more!

    installation

    npm install androidjs
    
    Enter fullscreen mode Exit fullscreen mode

    Install Android JS project generator and builder

    npm install -g androidjs-builder
    
    Enter fullscreen mode Exit fullscreen mode

    initialize

    mkdir AndroidApp
    cd AndroidApp
    androidjs g
    npm install
    
    Enter fullscreen mode Exit fullscreen mode

    it will generate a sample project inside AndroidApp directory.

    Which will look like:

    AndroidApp
        |__ assets
        |       |__ ipc, css, js
        |
        |__ views
        |       |__ index.html
        |
        |__ main.js
        |__ package.json
    
    Enter fullscreen mode Exit fullscreen mode
    • main.js is the main file or we can say it is back process of your app which execute all the code written in node, so you have to write all the node js code inside main.js
    • index.html is the first view which is render by app initially
    • package.json to keep track of all your node packages
    • assets to store all assets of your app

    time to build

    cd AndroidApp
    androidjs b
    
    Enter fullscreen mode Exit fullscreen mode

    it will generate apk file inside dist folder

    if this build command fails or generated any error, try to build with force command

    androidjs b -f
    
    Enter fullscreen mode Exit fullscreen mode

    Why not to use it

    Android.js isn't better than react-native
    But, at least you can (somewhat) throw your existing code in it and generate an API to work on a device just like android application.
    React native stays the best way to make Android applications with react (JavaScript).

    other resources

    docs - documentation for android.js

    Sample apps - some sample apps to go with..

    conclusion

    Android.js is an amazing framework if you don't know react

    But if you know react, react native comes in handy at the first place.

    originally published here at my blog

    Make sure you're subscribed to the high dose javascript newsletter

    of course I can't make you, but it take me a considerable amount of time to write these..

    tweet this if you like it.
    thanks!

    Jožica Lidiya 2022-08-11
    Is there a convenient way to create Parcelable data classes in Android with Kotlin?

    I'm currently using the excellent AutoParcel in my Java project, which facilitates the creation of Parcelable classes.

    Now, Kotlin, which I consider for my next project, has this concept of data classes, that automatically generate the equals, hashCode and toString methods.

    Is there a convenient way to make a Kotlin data class Parcelable in a convenient way (without implementing the methods manually)?

    Jana Lailoken 2022-08-15
    java - How to launch an Activity from another Application in Android

    I want to launch an installed package from my Android application. I assume that it is possible using intents, but I didn't find a way of doing it. Is there a link, where to find the information?

    Edna Morgen 2022-08-14
    java - onActivityResult() not called in new nested fragment API

    I have been using the new nested fragment API that Android includes in the support library.

    The problem that I am facing with nested fragments is that, if a nested fragment (that is, a fragment that has been added to another fragment via the FragmentManagerreturned by getChildFragmentManager()) calls startActivityForResult(), the nested fragment's onActivityResult() method is not called. However, both the parent fragment's onActivityResult() and activity's onActivityResult() do get called.

    I don't know if I am missing something about nested fragments, but I did not expect the described behavior. Below is the code that reproduces this problem. I would very much appreciate if someone can point me in the right direction and explain to me what I am doing wrong:

    package com.example.nestedfragmentactivityresult;
    
    import android.media.RingtoneManager;
    import android.os.Bundle;
    import android.content.Intent;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentActivity;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.Button;
    import android.widget.Toast;
    
    public class MainActivity extends FragmentActivity
    {
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            this.getSupportFragmentManager()
                .beginTransaction()
                .add(android.R.id.content, new ContainerFragment())
                .commit();
        }
    
        public void onActivityResult(int requestCode, int resultCode, Intent data)
        {
            super.onActivityResult(requestCode, resultCode, data);
    
            // This is called
            Toast.makeText(getApplication(),
                "Consumed by activity",
                Toast.LENGTH_SHORT).show();
        }
    
        public static class ContainerFragment extends Fragment
        {
            public final View onCreateView(LayoutInflater inflater,
                                           ViewGroup container,
                                           Bundle savedInstanceState)
            {
                View result = inflater.inflate(R.layout.test_nested_fragment_container,
                    container,
                    false);
    
                return result;
            }
    
            public void onActivityCreated(Bundle savedInstanceState)
            {
                super.onActivityCreated(savedInstanceState);
                getChildFragmentManager().beginTransaction()
                    .add(R.id.content, new NestedFragment())
                    .commit();
            }
    
            public void onActivityResult(int requestCode,
                                         int resultCode,
                                         Intent data)
            {
                super.onActivityResult(requestCode, resultCode, data);
    
                // This is called
                Toast.makeText(getActivity(),
                    "Consumed by parent fragment",
                    Toast.LENGTH_SHORT).show();
            }
        }
    
        public static class NestedFragment extends Fragment
        {
            public final View onCreateView(LayoutInflater inflater,
                                           ViewGroup container,
                                           Bundle savedInstanceState)
            {
                Button button = new Button(getActivity());
                button.setText("Click me!");
                button.setOnClickListener(new View.OnClickListener()
                {
                    public void onClick(View v)
                    {
                        Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
                        startActivityForResult(intent, 0);
                    }
                });
    
                return button;
            }
    
            public void onActivityResult(int requestCode,
                                         int resultCode,
                                         Intent data)
            {
                super.onActivityResult(requestCode, resultCode, data);
    
                // This is NOT called
                Toast.makeText(getActivity(),
                    "Consumed by nested fragment",
                    Toast.LENGTH_SHORT).show();
            }
        }
    }
    

    test_nested_fragment_container.xml is:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
    </FrameLayout>
    
    Emmy Kanani 2022-08-18
    android - How can I resolve the error "The minCompileSdk (31) specified in a dependency's AAR metadata" in native Java or Kotlin?

    The error message:

    The minCompileSdk (31) specified in a dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) is greater than this module's compileSdkVersion (android-30). Dependency: androidx.core:core-ktx:1.7.0-alpha02.

    AAR metadata file:
    C:\Users\mohammad.zeeshan1.gradle\caches\transforms-2\files-2.1\a20beb0771f59a8ddbbb8d416ea06a9d\jetified-core-ktx-1.7.0-alpha02\META-INF\com\android\build\gradle\aar-metadata.properties.

    Lenuța Robert 2022-08-15
    java - Android vibrate is deprecated. How to use VibrationEffect in Android>= API 26?

    I am using Android's VIBRATOR_SERVICE to give a haptic feedback for a button touch.

     ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(300);
    

    Android Studio give me warning that method vibrate(interval) is deprecated I should use VibrationEffect for API>23.

    So I usedVibrationEffect's method createOneShot which takes 2 params: interval, and amplitude. enter image description here

    I tried searching for it but got no clue about what to pass as amplitude, anybody got any idea about how to use it?

    Update Added code

    // Vibrate for 150 milliseconds
    private void shakeItBaby() {
        if (Build.VERSION.SDK_INT >= 26) {
            ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(VibrationEffect.createOneShot(150,10));
        } else {
            ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(150);
        }
    }
    
    Pétur Gulnara 2022-08-19
    java - Round Double to 1 decimal place kotlin: from 0.044999 to 0.1

    I have a Double variable that is 0.0449999 and I would like to round it to 1 decimal place 0.1 .

    I am using Kotlin but the Java solution is also helpful.

    val number:Double = 0.0449999

    I tried getting 1 decimal place with these two solutions:

    1. val solution = Math.round(number * 10.0) / 10.0
    2. val solution = String.format("%.1f", number)

    The problem is that I get 0.0 in both cases because it rounds the number from 0.04 to 0.0. It doesn't take all decimals and round it.

    I would like to obtain 0.1: 0.045 -> 0.05 -> 0.1

    Bóthildr Vilma 2022-08-17
    java - Android: How to Enable/Disable Wifi or Internet Connection Programmatically

    Using the Connectivity Manager Class we can get access to either wifi or Internet Network:

    ConnectivityManager connec = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    
    // ARE WE CONNECTED TO THE NET
    if ( connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED ||
      connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED ) {
      // ...
    }
    

    where 0 and 1 respectively refers to mobile and wifi connection

    If my Android device is connected to both, can we switch between any of the networks or can we disable any of the networks? Like using a function:

    connec.getNetworkInfo(0).setState(NetworkInfo.State.DISCONNECTED);
    
    Karthikeyan Dimos 2022-08-17
    android - How to create constructor of custom view with Kotlin

    I'm trying to use Kotlin in my Android project. I need to create custom view class. Each custom view has two important constructors:

    public class MyView extends View {
        public MyView(Context context) {
            super(context);
        }
    
        public MyView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    }
    

    MyView(Context) is used to instantiate view in code, and MyView(Context, AttributeSet) is called by layout inflater when inflating layout from XML.

    Answer to this question suggests that I use constructor with default values or factory method. But here's what we have:

    Factory method:

    fun MyView(c: Context) = MyView(c, attrs) //attrs is nowhere to get
    class MyView(c: Context, attrs: AttributeSet) : View(c, attrs) { ... }
    

    or

    fun MyView(c: Context, attrs: AttributeSet) = MyView(c) //no way to pass attrs.
                                                            //layout inflater can't use 
                                                            //factory methods
    class MyView(c: Context) : View(c) { ... }
    

    Constructor with default values:

    class MyView(c: Context, attrs: AttributeSet? = null) : View(c, attrs) { ... }
    //here compiler complains that 
    //"None of the following functions can be called with the arguments supplied."
    //because I specify AttributeSet as nullable, which it can't be.
    //Anyway, View(Context,null) is not equivalent to View(Context,AttributeSet)
    

    How can this puzzle be resolved?


    UPDATE: Seems like we can use View(Context, null) superclass constructor instead of View(Context), so factory method approach seems to be the solution. But even then I can't get my code to work:

    fun MyView(c: Context) = MyView(c, null) //compilation error here, attrs can't be null
    class MyView(c: Context, attrs: AttributeSet) : View(c, attrs) { ... }
    

    or

    fun MyView(c: Context) = MyView(c, null) 
    class MyView(c: Context, attrs: AttributeSet?) : View(c, attrs) { ... }
    //compilation error: "None of the following functions can be called with 
    //the arguments supplied." attrs in superclass constructor is non-null
    
    Yitro Usman 2022-08-18
    android - Kotlin - How to add OnPageChangeListener in ViewPager

    I am new in kotlin, How can I add OnPageChangeListener in a ViewPager.

    viewPager?.addOnPageChangeListener // Now how can I add listener to it.
    
    Lalage Yakiv 2022-08-21
    kotlin - Type Android Junit4 not present exception

    I have an Android project that I am trying to run Instrumentation tests for using AndroidStudio, but when I try to run the whole class file for the tests, I get the exceptions as stated below :

    java.lang.TypeNotPresentException: Type android.support.test.runner.AndroidJUnit4 not present
    Caused by: java.lang.ClassNotFoundException: android.support.test.runner.AndroidJUnit4
    

    Interestingly, I can run individual methods in this Instrument Test class, just not the whole class. My build.gradle file for the app is below:

    apply plugin: 'com.android.application'
    
    apply plugin: 'kotlin-android'
    
    apply plugin: 'kotlin-android-extensions'
    
    android {
        lintOptions {
            abortOnError false
        }
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.sarpuner.journal"
            minSdkVersion 19
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
        buildToolsVersion '27.0.3'
    }
    
    repositories {
        maven { url "https://dl.bintray.com/ijabz/maven" }
    }
    
    dependencies {
        androidTestImplementation 'com.android.support:support-annotations:27.1.1'
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
        implementation 'com.android.support.constraint:constraint-layout:1.1.2'
        implementation 'dev.dworks.libs:volleyplus:0.1.4'
        implementation 'com.google.code.gson:gson:2.8.2'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:rules:1.0.2'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'org.jsoup:jsoup:1.11.3'
        testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.1'
        implementation 'net.jthink:jaudiotagger:2.2.3'
        api 'com.google.guava:guava:26.0-android'
    }
    

    And the InstrumentTest class is as follows:

    package com.sarpuner.journal
    
    import android.support.test.InstrumentationRegistry
    import android.support.test.runner.AndroidJUnit4
    import android.util.Log    
    import org.junit.Test
    import org.junit.runner.RunWith    
    import org.junit.Assert.*
    import java.io.File
    
    private const val INSTRUMENT_TAG = "InstrumentTest"
    
    // TODO: There is a problem here with the class run!
    
    @RunWith(AndroidJUnit4::class)
    class ExampleInstrumentedTest {
    
        private val appContext = InstrumentationRegistry.getTargetContext()
    
        @Test
        fun useAppContext() {
            // Context of the app under test.
            assertEquals("com.sarpuner.journal", appContext.packageName)
        }
    
        @Test
        fun downloadAndSaveAudio() {
            val url = "http://telechargement.rfi.fr/rfi/francais/audio/jff/201808/journal_francais_facile_20h00_-_20h10_tu_20180809.mp3"
            val name = "09-08-2018.mp3"
            val f = File(appContext.filesDir, name)
            Log.d(INSTRUMENT_TAG, f.absolutePath)
            downloadAudio(url, f)
        }
    
        @Test
        fun downloadAndSaveTranscript() {
            val url = "https://savoirs.rfi.fr/fr/apprendre-enseigner/langue-francaise/journal-en-francais-facile-09082018-20h00-gmt"
            val name = "09-08-2018.txt"
            val f = File(appContext.filesDir, name)
    
            downloadText(url, f)
        }
    
        @Test
        fun addLyricsToAudio() {
    
        }
    }
    

    Any help/guidance is much appreciated, thank you.

    Louella Eleonora 2022-08-21
    android - Java String class replaceAll method missing

    I'm having a very weird issue right now, the replaceAll method is missing from the String object.

    JDK version: 1.8.0
    Android Studio version: 3.1.3
    Kotlin version: 1.2

    enter image description here

    It hasn't been removed, so whats going on here??

    Marko Yalwa 2022-08-21
    android - Unit testing coroutines runBlockingTest: This job has not completed yet

    Please find below a function using a coroutine to replace callback :

    override suspend fun signUp(authentication: Authentication): AuthenticationError {
        return suspendCancellableCoroutine {
            auth.createUserWithEmailAndPassword(authentication.email, authentication.password)
                .addOnCompleteListener(activityLifeCycleService.getActivity()) { task ->
                    if (task.isSuccessful) {
                        it.resume(AuthenticationError.SignUpSuccess)
                    } else {
                        Log.w(this.javaClass.name, "createUserWithEmail:failure", task.exception)
                        it.resume(AuthenticationError.SignUpFail)
                    }
                }
        }
    }
    

    Now I would like to unit testing this function. I am using Mockk :

      @Test
      fun `signup() must be delegated to createUserWithEmailAndPassword()`() = runBlockingTest {
    
          val listener = slot<OnCompleteListener<AuthResult>>()
          val authentication = mockk<Authentication> {
            every { email } returns "email"
            every { password } returns "pswd"
          }
          val task = mockk<Task<AuthResult>> {
            every { isSuccessful } returns true
          }
    
          every { auth.createUserWithEmailAndPassword("email", "pswd") } returns
              mockk {
                every { addOnCompleteListener(activity, capture(listener)) } returns mockk()
              }
    
        service.signUp(authentication)
    
          listener.captured.onComplete(task)
        }
    

    Unfortunately this test failed due to the following exception : java.lang.IllegalStateException: This job has not completed yet

    I tried to replace runBlockingTest with runBlocking but the test seems to wait in an infinite loop.

    Can someone help me with this UT please?

    Thanks in advance

    Elise Pankaj 2022-08-19
    Android Kotlin onItemSelectedListener for spinner not working

    I have a spinner with some items (strings). I want to add the selected items to a list. I read online that I should use the onItemSelectedListenerrather than the onItemClickListener.

    I implemented this but I don't know how to complete the step of adding it to the list.

    class NewKitListActivity : AppCompatActivity() {
    
    var spinnerArray = arrayOf("Dumbell", "Punching Bag", "Yoga Ball", "Skipping Rope")
    //var spinnerArray = arrayOf(DataService.kitList)
    
    
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_new_kit_list)
    
    
    
        val spinner = newKitItemSpinner
        val spinnerArrayAdapter = ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray)
        //selected item will look like a spinner set from XML
        spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
        spinner.adapter = spinnerArrayAdapter
    
        spinner.onItemSelectedListener = object : OnItemSelectedListener {
            override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
                val selectedItem = parent.getItemAtPosition(position).toString()
                if (selectedItem == "Add new category") {
                    // do your stuff
                }
            } // to close the onItemSelected
    
            override fun onNothingSelected(parent: AdapterView<*>) {
    
            }
        }}}
    

    Thanks

    Geordie Andrus 2022-08-19
    android - Kotlin Error : Could not find org.jetbrains.kotlin:kotlin-stdlib-jre7:1.0.7

    I installed the Kotlin plugin into my app (v. v1.1.1-release-Studio2.2-1) and then selected "Configure Kotlin in Project" I selected compiler and runtime version of 1.0.7. Kotlin updated my Gradle files. Now when I try to build in I get:

    Error: A problem occurred configuring project ':app'. Could not resolve all dependencies for configuration ':app:_debugApkCopy'. Could not find org.jetbrains.kotlin:kotlin-stdlib-jre7:1.0.7. Required by:

    MyApplication:app:unspecified

    I'm not sure what I'm missing here.

    Geordie Andrus 2022-08-15
    kotlin - How to create a Worker with parameters for in WorkManager for Android?

    Android architecture has a new components WorkManager.

    From the example,

    class CompressWorker(context : Context, params : WorkerParameters)
        : Worker(context, params) {
    
        override fun doWork(): Result {
    
            // Do the work here--in this case, compress the stored images.
            // In this example no parameters are passed; the task is
            // assumed to be "compress the whole library."
            myCompress()
    
            // Indicate success or failure with your return value:
            return Result.SUCCESS
    
            // (Returning RETRY tells WorkManager to try this task again
            // later; FAILURE says not to try again.)
    
        }
    
    }
    
    val compressionWork = OneTimeWorkRequestBuilder<CompressWorker>().build()
    

    How can I create a Worker that accept parameters in constructor or doWork?

    Wangchuk Lidochka 2022-08-21
    android - Kotlin: Iterate through a JSONArray

    I'm writing an Android app using Kotlin and Realm. I have a JSONArray, and I want to iterate through the JSONObjects in this array in order to load them in a Realm database class:

    Realm class:

    import io.realm.RealmObject
    import io.realm.annotations.PrimaryKey
    import io.realm.annotations.Required
    
    open class Person(
    
            @PrimaryKey open var id: Long = 0,
    
            @Required
            open var name: String = ""
    
    ) : RealmObject() {
    
    }
    

    The JSONArray:

    {
        "persons":[
            {
               "id":0,
               "name":"Biatrix"
            },
            {
               "id":1,
               "name":"Bill"
            },
            {
               "id":2,
               "name":"Oren"
            },
            {
               "id":3,
               "name":"Budd"
            }
        ]
    }
    

    I've tried iterating like the following:

    for (item : JSONObject in persons) {
    
    }
    

    ... but I get a for-loop range must have an iterator() method error.

    Ibrahim Yaron 2022-08-17
    java - How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?

    From Android 9 Pie now, requests without encryption will never work. And by default, the System will expect you to use TLS by default.You can read this feature here So if you only make requests via HTTPS you are safe. But what about apps that make requests through different sites, for instance, browser-like apps.

    How can I enable requests to all types of connections HTTP and HTTPS in Android 9 Pie?

    Destinee Nedyalko 2022-08-15
    Kotlin Android start new Activity

    I want to start another activity on Android but I get this error:

    Please specify constructor invocation; classifier 'Page2' does not have a companion object

    after instantiating the Intent class. What should I do to correct the error? My code:

    class MainActivity : AppCompatActivity() {
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
        }
    
        fun buTestUpdateText2 (view: View) {
            val changePage = Intent(this, Page2) 
            // Error: "Please specify constructor invocation; 
            // classifier 'Page2' does not have a companion object"
    
            startActivity(changePage)
        }
    
    }
    
    Laxmi Queenie 2022-08-16
    kotlin - Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException

    I update my Android Studio (3.2.1) and its sdk to the latest version. After that it required a manual update for Manifest by adding these tags:

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@drawable/ic_launcher"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="AllowBackup,GoogleAppIndexingWarning">
    
        <meta-data
            android:name="com.google.android.gms.ads.APP_ID"
            android:value="ca-app-pub-#############"/>
    
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".NewActivity" />
        <activity android:name=".PreviewActivity" />
        <activity android:name=".EditActivity" />
        <activity
            android:name=".preferencesdata.AboutActivity"
            android:theme="@style/Theme.AppCompat.DayNight.NoActionBar" />
        <activity android:name=".preferencesdata.SettingsActivity"
            android:label="@string/settings">
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value=".MainActivity"/>
        </activity>
    </application>
    

    whereby instead the app ID I put the real id of my app. The value has also been changed to the right Ad Unit id as shown here https://developers.google.com/admob/android/quick-start. I also called this function in the MainActivity.kt:

    MobileAds.initialize(this, resources.getString(R.string.banner_ad_unit_id)) 
    

    However, the problem could not be solved. It still prints as follows:

    E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.easyapps.cryptnote, PID: 3991
        java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: 
    
        ******************************************************************************
        * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
        * should follow the instructions LINK to add a valid  *
        * App ID inside the AndroidManifest. Google Ad Manager publishers should     *
        * follow instructions here: LINK.                           *
        ******************************************************************************
    
    
            at android.app.ActivityThread.installProvider(ActivityThread.java:5156)
            at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)
            at android.app.ActivityThread.-wrap1(ActivityThread.java)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:148)
            at android.app.ActivityThread.main(ActivityThread.java:5417)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
         Caused by: java.lang.IllegalStateException: 
    
        ******************************************************************************
        * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
        * should follow the instructions here: LINK to add a valid  *
        * App ID inside the AndroidManifest. Google Ad Manager publishers should     *
        * follow instructions here: LINK.                           *
        ******************************************************************************
    
    
            at com.google.android.gms.internal.ads.zzmn.attachInfo(Unknown Source)
            at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(Unknown Source)
            at android.app.ActivityThread.installProvider(ActivityThread.java:5153)
                ... 10 more
    

    Could someone tel me why it does happen or help me to solve it? I tried to google the issue, but there are no solutions. It seems to be an a new still unsolved issue. Many thanks in advance.

    Vimal Anderson 2022-08-18
    android - RegisterResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)

    Using new android studio with new 3.0.0 Gradle pluging.
    When building some warning happened:

    registerResGeneratingTask is deprecated, use
    registerGeneratedFolders(FileCollection)
    
    Seher Ernesto 2022-08-15
    java - Why and when to use @JvmStatic with companion objects?

    I'm trying to understand the difference between using/not using @JvmStatic, and when I should use either one.

    So, with Kotlin and Java, I can do this:

    TestKotlin.kt

    class TestKotlin {
        companion object {
            val someString = "hello world"
        }
    }
    

    Which is then called by Java, like this:

    TestJava.java

    public class TestJava {
        String kotlinStaticString = TestKotlin.Companion.getSomeString();
    }
    

    but then, there's this option 2:

    TestKotlin.kt v2

    class TestKotlin {
        companion object {
            @JvmStatic  // <-- notice the @JvmStatic annotation
            val someString = "hello world"
        }
    }
    

    And then, call it from Java, like this:

    TestJava.java v2

    public class TestJava {
        String kotlinStaticString = TestKotlin.getSomeString();
    }
    

    So my questions are:

    • Are these 2 cases any different, in terms of behavior or memory allocation?
    • Is there a preference on which one to use?
    • Do both create a pseudo static singleton object, like Java static does?

    Thanks!

    Wangchuk Balduíno 2022-08-17
    kotlin - material-1.5.0-alpha03
esvalues-v31values-v31.xml:3:5-94: AAPT: error: resource android:color/system_neutral1_1000 not found
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <color name="m3_ref_palette_dynamic_neutral0">@android:color/system_neutral1_1000</color>
        <color name="m3_ref_palette_dynamic_neutral10">@android:color/system_neutral1_900</color>
        <color name="m3_ref_palette_dynamic_neutral100">@android:color/system_neutral1_0</color>
        <color name="m3_ref_palette_dynamic_neutral20">@android:color/system_neutral1_800</color>
        <color name="m3_ref_palette_dynamic_neutral30">@android:color/system_neutral1_700</color>
        <color name="m3_ref_palette_dynamic_neutral40">@android:color/system_neutral1_600</color>
        <color name="m3_ref_palette_dynamic_neutral50">@android:color/system_neutral1_500</color>
        <color name="m3_ref_palette_dynamic_neutral60">@android:color/system_neutral1_400</color>
        <color name="m3_ref_palette_dynamic_neutral70">@android:color/system_neutral1_300</color>
        <color name="m3_ref_palette_dynamic_neutral80">@android:color/system_neutral1_200</color>
        <color name="m3_ref_palette_dynamic_neutral90">@android:color/system_neutral1_100</color>
        <color name="m3_ref_palette_dynamic_neutral95">@android:color/system_neutral1_50</color>
        <color name="m3_ref_palette_dynamic_neutral99">@android:color/system_neutral1_10</color>
        <color name="m3_ref_palette_dynamic_neutral_variant0">@android:color/system_neutral2_1000</color>
        <color name="m3_ref_palette_dynamic_neutral_variant10">@android:color/system_neutral2_900</color>
        <color name="m3_ref_palette_dynamic_neutral_variant100">@android:color/system_neutral2_0</color>
        <color name="m3_ref_palette_dynamic_neutral_variant20">@android:color/system_neutral2_800</color>
        <color name="m3_ref_palette_dynamic_neutral_variant30">@android:color/system_neutral2_700</color>
        <color name="m3_ref_palette_dynamic_neutral_variant40">@android:color/system_neutral2_600</color>
        <color name="m3_ref_palette_dynamic_neutral_variant50">@android:color/system_neutral2_500</color>
        <color name="m3_ref_palette_dynamic_neutral_variant60">@android:color/system_neutral2_400</color>
        <color name="m3_ref_palette_dynamic_neutral_variant70">@android:color/system_neutral2_300</color>
        <color name="m3_ref_palette_dynamic_neutral_variant80">@android:color/system_neutral2_200</color>
        <color name="m3_ref_palette_dynamic_neutral_variant90">@android:color/system_neutral2_100</color>
        <color name="m3_ref_palette_dynamic_neutral_variant95">@android:color/system_neutral2_50</color>
        <color name="m3_ref_palette_dynamic_neutral_variant99">@android:color/system_neutral2_10</color>
        <color name="m3_ref_palette_dynamic_primary0">@android:color/system_accent1_1000</color>
        <color name="m3_ref_palette_dynamic_primary10">@android:color/system_accent1_900</color>
        <color name="m3_ref_palette_dynamic_primary100">@android:color/system_accent1_0</color>
        <color name="m3_ref_palette_dynamic_primary20">@android:color/system_accent1_800</color>
        <color name="m3_ref_palette_dynamic_primary30">@android:color/system_accent1_700</color>
        <color name="m3_ref_palette_dynamic_primary40">@android:color/system_accent1_600</color>
        <color name="m3_ref_palette_dynamic_primary50">@android:color/system_accent1_500</color>
        <color name="m3_ref_palette_dynamic_primary60">@android:color/system_accent1_400</color>
        <color name="m3_ref_palette_dynamic_primary70">@android:color/system_accent1_300</color>
        <color name="m3_ref_palette_dynamic_primary80">@android:color/system_accent1_200</color>
        <color name="m3_ref_palette_dynamic_primary90">@android:color/system_accent1_100</color>
        <color name="m3_ref_palette_dynamic_primary95">@android:color/system_accent1_50</color>
        <color name="m3_ref_palette_dynamic_primary99">@android:color/system_accent1_10</color>
        <color name="m3_ref_palette_dynamic_secondary0">@android:color/system_accent2_1000</color>
        <color name="m3_ref_palette_dynamic_secondary10">@android:color/system_accent2_900</color>
        <color name="m3_ref_palette_dynamic_secondary100">@android:color/system_accent2_0</color>
        <color name="m3_ref_palette_dynamic_secondary20">@android:color/system_accent2_800</color>
        <color name="m3_ref_palette_dynamic_secondary30">@android:color/system_accent2_700</color>
        <color name="m3_ref_palette_dynamic_secondary40">@android:color/system_accent2_600</color>
        <color name="m3_ref_palette_dynamic_secondary50">@android:color/system_accent2_500</color>
        <color name="m3_ref_palette_dynamic_secondary60">@android:color/system_accent2_400</color>
        <color name="m3_ref_palette_dynamic_secondary70">@android:color/system_accent2_300</color>
        <color name="m3_ref_palette_dynamic_secondary80">@android:color/system_accent2_200</color>
        <color name="m3_ref_palette_dynamic_secondary90">@android:color/system_accent2_100</color>
        <color name="m3_ref_palette_dynamic_secondary95">@android:color/system_accent2_50</color>
        <color name="m3_ref_palette_dynamic_secondary99">@android:color/system_accent2_10</color>
        <color name="m3_ref_palette_dynamic_tertiary0">@android:color/system_accent3_1000</color>
        <color name="m3_ref_palette_dynamic_tertiary10">@android:color/system_accent3_900</color>
        <color name="m3_ref_palette_dynamic_tertiary100">@android:color/system_accent3_0</color>
        <color name="m3_ref_palette_dynamic_tertiary20">@android:color/system_accent3_800</color>
        <color name="m3_ref_palette_dynamic_tertiary30">@android:color/system_accent3_700</color>
        <color name="m3_ref_palette_dynamic_tertiary40">@android:color/system_accent3_600</color>
        <color name="m3_ref_palette_dynamic_tertiary50">@android:color/system_accent3_500</color>
        <color name="m3_ref_palette_dynamic_tertiary60">@android:color/system_accent3_400</color>
        <color name="m3_ref_palette_dynamic_tertiary70">@android:color/system_accent3_300</color>
        <color name="m3_ref_palette_dynamic_tertiary80">@android:color/system_accent3_200</color>
        <color name="m3_ref_palette_dynamic_tertiary90">@android:color/system_accent3_100</color>
        <color name="m3_ref_palette_dynamic_tertiary95">@android:color/system_accent3_50</color>
        <color name="m3_ref_palette_dynamic_tertiary99">@android:color/system_accent3_10</color>
        <color name="m3_sys_color_dynamic_dark_background">@color/m3_ref_palette_dynamic_neutral10</color>
        <color name="m3_sys_color_dynamic_dark_inverse_on_surface">@color/m3_ref_palette_dynamic_neutral20</color>
        <color name="m3_sys_color_dynamic_dark_inverse_primary">@color/m3_ref_palette_dynamic_primary40</color>
        <color name="m3_sys_color_dynamic_dark_inverse_surface">@color/m3_ref_palette_dynamic_neutral90</color>
        <color name="m3_sys_color_dynamic_dark_on_background">@color/m3_ref_palette_dynamic_neutral90</color>
        <color name="m3_sys_color_dynamic_dark_on_primary">@color/m3_ref_palette_dynamic_primary20</color>
        <color name="m3_sys_color_dynamic_dark_on_primary_container">@color/m3_ref_palette_dynamic_primary90</color>
        <color name="m3_sys_color_dynamic_dark_on_secondary">@color/m3_ref_palette_dynamic_secondary20</color>
        <color name="m3_sys_color_dynamic_dark_on_secondary_container">@color/m3_ref_palette_dynamic_secondary90</color>
        <color name="m3_sys_color_dynamic_dark_on_surface">@color/m3_ref_palette_dynamic_neutral90</color>
        <color name="m3_sys_color_dynamic_dark_on_surface_variant">@color/m3_ref_palette_dynamic_neutral_variant80</color>
        <color name="m3_sys_color_dynamic_dark_on_tertiary">@color/m3_ref_palette_dynamic_tertiary20</color>
        <color name="m3_sys_color_dynamic_dark_on_tertiary_container">@color/m3_ref_palette_dynamic_tertiary90</color>
        <color name="m3_sys_color_dynamic_dark_outline">@color/m3_ref_palette_dynamic_neutral_variant60</color>
        <color name="m3_sys_color_dynamic_dark_primary">@color/m3_ref_palette_dynamic_primary80</color>
        <color name="m3_sys_color_dynamic_dark_primary_container">@color/m3_ref_palette_dynamic_primary30</color>
        <color name="m3_sys_color_dynamic_dark_secondary">@color/m3_ref_palette_dynamic_secondary80</color>
        <color name="m3_sys_color_dynamic_dark_secondary_container">@color/m3_ref_palette_dynamic_secondary30</color>
        <color name="m3_sys_color_dynamic_dark_surface">@color/m3_ref_palette_dynamic_neutral10</color>
        <color name="m3_sys_color_dynamic_dark_surface_variant">@color/m3_ref_palette_dynamic_neutral_variant30</color>
        <color name="m3_sys_color_dynamic_dark_tertiary">@color/m3_ref_palette_dynamic_tertiary80</color>
        <color name="m3_sys_color_dynamic_dark_tertiary_container">@color/m3_ref_palette_dynamic_tertiary30</color>
        <color name="m3_sys_color_dynamic_light_background">@color/m3_ref_palette_dynamic_neutral99</color>
        <color name="m3_sys_color_dynamic_light_inverse_on_surface">@color/m3_ref_palette_dynamic_neutral95</color>
        <color name="m3_sys_color_dynamic_light_inverse_primary">@color/m3_ref_palette_dynamic_primary80</color>
        <color name="m3_sys_color_dynamic_light_inverse_surface">@color/m3_ref_palette_dynamic_neutral20</color>
        <color name="m3_sys_color_dynamic_light_on_background">@color/m3_ref_palette_dynamic_neutral10</color>
        <color name="m3_sys_color_dynamic_light_on_primary">@color/m3_ref_palette_dynamic_primary100</color>
        <color name="m3_sys_color_dynamic_light_on_primary_container">@color/m3_ref_palette_dynamic_primary10</color>
        <color name="m3_sys_color_dynamic_light_on_secondary">@color/m3_ref_palette_dynamic_secondary100</color>
        <color name="m3_sys_color_dynamic_light_on_secondary_container">@color/m3_ref_palette_dynamic_secondary10</color>
        <color name="m3_sys_color_dynamic_light_on_surface">@color/m3_ref_palette_dynamic_neutral10</color>
        <color name="m3_sys_color_dynamic_light_on_surface_variant">@color/m3_ref_palette_dynamic_neutral_variant30</color>
        <color name="m3_sys_color_dynamic_light_on_tertiary">@color/m3_ref_palette_dynamic_tertiary100</color>
        <color name="m3_sys_color_dynamic_light_on_tertiary_container">@color/m3_ref_palette_dynamic_tertiary10</color>
        <color name="m3_sys_color_dynamic_light_outline">@color/m3_ref_palette_dynamic_neutral_variant50</color>
        <color name="m3_sys_color_dynamic_light_primary">@color/m3_ref_palette_dynamic_primary40</color>
        <color name="m3_sys_color_dynamic_light_primary_container">@color/m3_ref_palette_dynamic_primary90</color>
        <color name="m3_sys_color_dynamic_light_secondary">@color/m3_ref_palette_dynamic_secondary40</color>
        <color name="m3_sys_color_dynamic_light_secondary_container">@color/m3_ref_palette_dynamic_secondary90</color>
        <color name="m3_sys_color_dynamic_light_surface">@color/m3_ref_palette_dynamic_neutral99</color>
        <color name="m3_sys_color_dynamic_light_surface_variant">@color/m3_ref_palette_dynamic_neutral_variant90</color>
        <color name="m3_sys_color_dynamic_light_tertiary">@color/m3_ref_palette_dynamic_tertiary40</color>
        <color name="m3_sys_color_dynamic_light_tertiary_container">@color/m3_ref_palette_dynamic_tertiary90</color>
        <style name="ThemeOverlay.Material3.DynamicColors.Dark" parent="">
        <!-- Color palettes -->
        <item name="colorPrimary">@color/m3_sys_color_dynamic_dark_primary</item>
        <item name="colorOnPrimary">@color/m3_sys_color_dynamic_dark_on_primary</item>
        <item name="colorPrimaryInverse">@color/m3_sys_color_dynamic_dark_inverse_primary</item>
        <item name="colorPrimaryContainer">@color/m3_sys_color_dynamic_dark_primary_container</item>
        <item name="colorOnPrimaryContainer">@color/m3_sys_color_dynamic_dark_on_primary_container</item>
        <item name="colorSecondary">@color/m3_sys_color_dynamic_dark_secondary</item>
        <item name="colorOnSecondary">@color/m3_sys_color_dynamic_dark_on_secondary</item>
        <item name="colorSecondaryContainer">@color/m3_sys_color_dynamic_dark_secondary_container</item>
        <item name="colorOnSecondaryContainer">@color/m3_sys_color_dynamic_dark_on_secondary_container</item>
        <item name="colorTertiary">@color/m3_sys_color_dynamic_dark_tertiary</item>
        <item name="colorOnTertiary">@color/m3_sys_color_dynamic_dark_on_tertiary</item>
        <item name="colorTertiaryContainer">@color/m3_sys_color_dynamic_dark_tertiary_container</item>
        <item name="colorOnTertiaryContainer">@color/m3_sys_color_dynamic_dark_on_tertiary_container</item>
        <item name="android:colorBackground">@color/m3_sys_color_dynamic_dark_background</item>
        <item name="colorOnBackground">@color/m3_sys_color_dynamic_dark_on_background</item>
        <item name="colorSurface">@color/m3_sys_color_dynamic_dark_surface</item>
        <item name="colorOnSurface">@color/m3_sys_color_dynamic_dark_on_surface</item>
        <item name="colorSurfaceVariant">@color/m3_sys_color_dynamic_dark_surface_variant</item>
        <item name="colorOnSurfaceVariant">@color/m3_sys_color_dynamic_dark_on_surface_variant</item>
        <item name="colorSurfaceInverse">@color/m3_sys_color_dynamic_dark_inverse_surface</item>
        <item name="colorOnSurfaceInverse">@color/m3_sys_color_dynamic_dark_inverse_on_surface</item>
        <item name="colorOutline">@color/m3_sys_color_dynamic_dark_outline</item>
        <item name="colorError">@color/m3_sys_color_dark_error</item>
        <item name="colorOnError">@color/m3_sys_color_dark_on_error</item>
        <item name="colorErrorContainer">@color/m3_sys_color_dark_error_container</item>
        <item name="colorOnErrorContainer">@color/m3_sys_color_dark_on_error_container</item>
      </style>
        <style name="ThemeOverlay.Material3.DynamicColors.DayNight" parent="ThemeOverlay.Material3.DynamicColors.Light"/>
        <style name="ThemeOverlay.Material3.DynamicColors.Light" parent="">
        <!-- Color palettes -->
        <item name="colorPrimary">@color/m3_sys_color_dynamic_light_primary</item>
        <item name="colorOnPrimary">@color/m3_sys_color_dynamic_light_on_primary</item>
        <item name="colorPrimaryInverse">@color/m3_sys_color_dynamic_light_inverse_primary</item>
        <item name="colorPrimaryContainer">@color/m3_sys_color_dynamic_light_primary_container</item>
        <item name="colorOnPrimaryContainer">@color/m3_sys_color_dynamic_light_on_primary_container</item>
        <item name="colorSecondary">@color/m3_sys_color_dynamic_light_secondary</item>
        <item name="colorOnSecondary">@color/m3_sys_color_dynamic_light_on_secondary</item>
        <item name="colorSecondaryContainer">@color/m3_sys_color_dynamic_light_secondary_container</item>
        <item name="colorOnSecondaryContainer">@color/m3_sys_color_dynamic_light_on_secondary_container</item>
        <item name="colorTertiary">@color/m3_sys_color_dynamic_light_tertiary</item>
        <item name="colorOnTertiary">@color/m3_sys_color_dynamic_light_on_tertiary</item>
        <item name="colorTertiaryContainer">@color/m3_sys_color_dynamic_light_tertiary_container</item>
        <item name="colorOnTertiaryContainer">@color/m3_sys_color_dynamic_light_on_tertiary_container</item>
        <item name="android:colorBackground">@color/m3_sys_color_dynamic_light_background</item>
        <item name="colorOnBackground">@color/m3_sys_color_dynamic_light_on_background</item>
        <item name="colorSurface">@color/m3_sys_color_dynamic_light_surface</item>
        <item name="colorOnSurface">@color/m3_sys_color_dynamic_light_on_surface</item>
        <item name="colorSurfaceVariant">@color/m3_sys_color_dynamic_light_surface_variant</item>
        <item name="colorOnSurfaceVariant">@color/m3_sys_color_dynamic_light_on_surface_variant</item>
        <item name="colorSurfaceInverse">@color/m3_sys_color_dynamic_light_inverse_surface</item>
        <item name="colorOnSurfaceInverse">@color/m3_sys_color_dynamic_light_inverse_on_surface</item>
        <item name="colorOutline">@color/m3_sys_color_dynamic_light_outline</item>
        <item name="colorError">@color/m3_sys_color_light_error</item>
        <item name="colorOnError">@color/m3_sys_color_light_on_error</item>
        <item name="colorErrorContainer">@color/m3_sys_color_light_error_container</item>
        <item name="colorOnErrorContainer">@color/m3_sys_color_light_on_error_container</item>
      </style>
    </resources>
    

    Here is my v31/values-v31

    While I'm trying to build this project . I'm frequently getting this error(

    ERROR:C:\Users\Dell.gradle\caches\transforms-2\files-2.1\66e9dd10963e7a2704a4a2116f19e6fb\material-1.5.0-alpha03\res\values-v31\values-v31.xml:3:5-94: AAPT: error: resource android:color/system_neutral1_1000 not found.)

    Solutions I tried Rebuild project, clean project, Invalidate cache and restart, enter code hereand also delete and newly create that emulator but nothing worked for me

    Filibert Nosizwe 2022-08-17
    android - How to set the part of the text view is clickable

    I have the text "Android is a Software stack". In this text i want to set the "stack" text as clickable. So, if you click on that it will redirected to a new activity(not in the browser).

    I tried but i am not getting a solution.

    Amalia Sopheap 2022-08-14
    android - what does "::" mean in kotlin?

    I'm new to Kotlin
    I used this code for opening another activity:

    startActivity(Intent(this,IntroAndLang::class.java))
    

    current activity and target activity are written in Kotlin

    I can't understand why there is not single : instead of :: at IntroAndLang::class.java

    Marie-José Brunihild 2022-08-17
    java - Kotlin-android: unresolved reference databinding

    I have following fragment class written in Java using the new databinding library

    import com.example.app.databinding.FragmentDataBdinding;
    
    public class DataFragment extends Fragment {
    
        @Nullable
        private FragmentDataBinding mBinding;
    
        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_data, container, false);
            return mBinding.getRoot();
        }
    }
    

    It compiles and runs fine.
    I tried to rewrite it in Kotlin and came up with the following:

    import com.example.app.databinding.FragmentDataBdinding
    
    class ProfileFragment : Fragment() {
    
        private var mBinding: FragmentDataBinding? = null
    
        override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
            mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_data, container, false)
            return mBinding!!.getRoot()
        }
    }
    

    But now step :app:compileDebugKotlin outputs the following:

    Error:(16, 38) Unresolved reference: databinding
    Error:(37, 27) Unresolved reference: FragmentDataBinding

    How can I use android-databinding library with Kotlin?

    My top-level build.gradle:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:1.3.0'
            classpath 'com.android.databinding:dataBinder:1.0-rc4'
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    

    My build.gradle in app dir (only relevant parts):

    apply plugin: 'com.android.application'
    apply plugin: 'com.android.databinding'
    apply plugin: 'kotlin-android'
    
    dependencies {
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    }
    
    buildscript {
        ext.kotlin_version = '0.14.451'
        repositories {
            mavenCentral()
        }
    
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
        }
    }
    repositories {
        mavenCentral()
        maven {
            url 'http://oss.sonatype.org/content/repositories/snapshots'
        }
    }
    

    I'm using Android Studio 1.4, Build tools version 23.0.1, Android SDK 23, SDK tools 24.4.0

    Cefin Polycarp 2022-08-15
    android - kotlin 'onCreate' overrides nothing

    I am using component development, in my common module BaseActivity.kt and BaseFragment.kt. The following problems occur when other modules inherit them

    > D:\Android\OneDaily\module_main\src\main\java\com\boco\main\MainActivity.kt
    > Error:(7, 24) Unresolved reference: base 
    > Error:(9, 22) Unresolved reference: BaseActivity 
    > Error:(21, 5) 'onCreate' overrides nothing
    > Error:(17, 5) 'getLayoutRes' overrides nothing 
    > Error:(22, 15) Unresolved reference: onCreate 
    > Error:(27, 22) Unresolved reference: findViewById 
    > Error:(42, 34) Unresolved reference: supportFragmentManager
    > D:\Android\OneDaily\module_main\src\main\java\com\boco\main\TimelineFragment.kt
    > Error:(7, 24) Unresolved reference: base 
    > Error:(10, 5) 'getLayoutRes' overrides nothing 
    > Error:(9, 26) Unresolved reference: BaseFragment
    > Error:(14, 5) 'onCreateView' overrides nothing 
    > Error:(15, 22) Unresolved reference: onCreateView
    

    BaseActivity.kt:

    abstract class BaseActivity : AppCompatActivity() {  
        init {  
            AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)  
        }  
        abstract fun getLayoutRes(): Int  
        override fun onCreate(savedInstanceState: Bundle?) {  
            super.onCreate(savedInstanceState)  
            setContentView(getLayoutRes())  
        }  
    }  
    

    MainActivity.kt

    class MainActivity : BaseActivity() {
    
        private lateinit var mBottomNav: BottomNavigationView
    
        private var mFragment1 = TimelineFragment() as Fragment
        private var mFragment2 = TimelineFragment() as Fragment
        private var mFragment3 = TimelineFragment() as Fragment
    
        override fun getLayoutRes(): Int {
            return R.layout.activity_main
        }
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
        }
    }
    
    Salvatrix Ngải 2022-08-21
    How to fix ERROR: No signature of method: build_ap86oam3dut3pxce3x49rdtma.android()?

    ERROR: No signature of method: build_ap86oam3dut3pxce3x49rdtma.android() is applicable for argument types: (build_ap86oam3dut3pxce3x49rdtma$_run_closure1) values: [build_ap86oam3dut3pxce3x49rdtma$_run_closure1@47588b04]

    The build gradle is:

    apply plugin: 'com.android.application'
    
        android{
        implementationSdkVersion 28
        buildToolsVersion "29.0.3"
        defaultConfig {
            applicationId "com.uiresource.taksiku"
            minSdkVersion 16
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            vectorDrawables.useSupportLibrary = true
        }
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
            }
        }
    
        dependencies {
            implementation fileTree(dir: 'libs', include: ['*.jar'])
            androidTestImplementation('com.android.support.test.espresso:espresso-core:2.3-alpha', {
                exclude group: 'com.android.support', module: 'support-annotations'
            })
            implementation "com.android.support:appcompat-v7:$var"
            implementation 'com.android.support:design:28.0.0'
            testimplementation 'junit:junit:4.13'
            implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta5'
            implementation 'de.hdodenhof:circleimageview:3.1.0'
            }
    
    Séafra Orvar 2022-08-16
    android - java.lang.IllegalStateException: Dex archives: setting .DEX extension only for .CLASS files

    I build the project at gitlab ci

    ./gradlew assembleDebug --stacktrace
    

    and sometimes it throws an error:

    FAILURE: Build failed with an exception.
    * What went wrong:
    Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
    > com.android.build.api.transform.TransformException: java.lang.IllegalStateException: Dex archives: setting .DEX extension only for .CLASS files
    

    At my local pc it works correctly.

    kotlin version is 1.2

    multidex is enabled

    What is the reason of this error?

    Sitora Meresankh 2022-08-19
    kotlin - android.view.View.systemUiVisibility deprecated. What is the replacement?

    I have updated the project target API version to 30, and now I see that the systemUiVisibility property is deprecated.

    The following kotlin code is the one I'm using which is actually equivalent to setSystemUiVisibility method in Java.

    playerView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LOW_PROFILE
                or View.SYSTEM_UI_FLAG_FULLSCREEN
                or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)
    

    Please let me know if you have got any stable replacement for this deprecated code. The google's recommendation is to use WindowInsetsController, but I don't how to do that.

    Alícia Ugochukwu 2022-08-16
    kotlin - Android Room - Select query with LIKE

    I'm trying to make a query to search all objects whose names contain text:

    @Query("SELECT * FROM hamster WHERE name LIKE %:arg0%")
    fun loadHamsters(search: String?): Flowable<List<Hamster>>
    

    Messages:

    Error:no viable alternative at input 'SELECT * FROM hamster WHERE name LIKE %'
    Error:There is a problem with the query: [SQLITE_ERROR] SQL error or missing database (near "%": syntax error)
    Error:Unused parameter: arg0
    

    Also, I'm trying:

    @Query("SELECT * FROM hamster WHERE name LIKE '%:arg0%'")
    fun loadHamsters(search: String?): Flowable<List<Hamster>>
    

    Messages:

    Error:Unused parameter: arg0
    

    How to fix this?

    Simon Yitro 2022-08-15