Problems with android studio development series

It's a reminder of the bugs I've had so far and "I'm checking this every time ..." Unless otherwise noted, android studio 3.0.1 + java 1.8.0

gradle build edition

Minimum supported Gradle version is 4.1. Current version is 2.14.1. https://qiita.com/izuki_y/items/26e5735a26a3494b4833#errorminimum-supported-gradle-version-is There is no version of gradle, so if you give it, it will be solved

Error: '.' is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore https://teratail.com/questions/130852 The file name is invalid error For some reason there were two `` `.``` before the extension, so fix it

Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version 14 declared in library [com.google.android.gms:play-services:11.0.4] https://qiita.com/naotsune/items/8a45fb5436b50d3fef56 Raise minSdkVersion error Raise and resolve

Error:Execution failed for task ':approcessDebugGoogleServices'. Full text ⬇︎

Error:Execution failed for task ':approcessDebugGoogleServices'.
>Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 12.0.1.

Occurs when adding an FCM package using the android studio function If you look closely, you can see the app build.gradle

implementation 'com.google.firebase:firebase-messaging:11.0.4'

Was an error. (The part automatically inserted by android studio) As you say, it will be solved if it is aligned with 12.0.1

Error:Unable to find method 'org.gradle.api.artifacts.Configuration.defaultDependencies Full text ⬇︎

Error:Unable to find method 'org.gradle.api.artifacts.Configuration.defaultDependencies(Lorg/gradle/api/Action;)Lorg/gradle/api/artifacts/Configuration;'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Try to download as you are told

I get the same error >https://stackoverflow.com/questions/37655814/gradle-sync-failed-unable-to-find-method https://android.benigumo.com/20180121/build-environment-stable/ I will give the version of build.gradle for reference (2.2.1 => 5.4.1) > Elimination

Error:No such property: GradleVersion for class: JetGradlePlugin

Postscript (2020/2/20)

https://cpoint-lab.co.jp/article/201908/11313/ According to it, the cause is that the version of android studio is lower than the version of gradle. So

--Updated android studio --Downgrading gradle

It seems that either one will solve the problem. Is it better to update unless there are special circumstances?

Previous work record

https://stackoverflow.com/questions/53600179/errorno-such-property-gradleversion-for-class-jetgradleplugin It seems that downgrading this time will solve the problem ... 5.4.1 => 4.10.1

It is said that tools cannot be found >https://developer.android.com/studio/releases/gradle-plugin.html#updating-gradle While looking at the correspondence table of

- com.android.tools.build:gradle:3.4.1
+ com.android.tools.build:gradle:3.3.0

To > It is said that it cannot be found yet >https://stackoverflow.com/questions/46316213/errorcould-not-find-com-android-tools-buildgradle3-3-issue-raise-after-upgra Add google () to build.gradle of PJ root for reference > For the time being

Error:Removing unused resources requires unused code shrinking to be turned on. https://stackoverflow.com/questions/52310841/removing-unused-resources-requires-unused-code-shrinking-to-be-turned-on app.gradle

- minifyEnabled false
+ minifyEnabled true

If you set it to

Compile

Error: Your project contains C++ files but it is not using a supported native build system. Occurs in PJ using cpp. You need to include the cpp compiler. Originally cmake is recommended, but abandoned due to an error ...

After installing NDK https://qiita.com/kenmasu/items/598496840eef775db142 Edit build.gradle for reference

Error:(177, 0) *** Android NDK: APP_STL stlport_static is no longer supported. Please switch to either c++_static or c++_shared. See https://developer.android.com/ndk/guides/cpp-support.html for more information.    .  Stop.

Came out https://github.com/google/ExoPlayer/issues/5052 Changed the reference of APP_STL of Application.mk to APP_STL: = c ++ _ shared > Elimination

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. An error that occurs when multiple dependencies conflict. I've encountered it many times, so here's an example

https://qiita.com/Capotasto/items/ad1824722da7c3d9da97 For the time being, look for the place where you are using the library mentioned in the error in `./gradlew app: dependencies``` This time I got angry with ``` Multiple dex files define Landroid / support / v4 / view / MotionEventCompat;`

~~~Omission~~~
+--- com.google.android.gms:play-services-base:12.0.1
|    +--- com.google.android.gms:play-services-basement:12.0.1
|    |    +--- com.android.support:support-v4:26.1.0
~~~Omission~~~

According to the above, it seems that com.google.android.gms: play-services-base: 12.0.1 is calling, so

compile ('com.google.android.gms:play-services-base:12.0.1') {
    exclude group: 'com.android.support', module: 'support-v4'
}

I will remove it from the dependency. You should be able to go with this

org.gradle.tooling.BuildException: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.10.2-all.zip'. The whole sentence was very long, so only the parts that seem to be relevant are excerpted

Error:Internal error:
org.gradle.tooling.BuildException: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-4.10.2-all.zip'.
Caused by: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':app:javaPreCompileDebug'.
Caused by: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:javaPreCompileDebug'.Caused by: java.lang.RuntimeException: Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.
  - butterknife-6.1.0.jar (com.jakewharton:butterknife:6.1.0)
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

https://stackoverflow.com/questions/47087730/why-do-i-have-problems-whith-com-jakewhartonbutterknife7-0-1-in-android-stud Modify app / build.gradle for reference

android {
    ~~~~~Omission~~~~~

    defaultConfig {
        ~~~~~Omission~~~~~
        //Postscript part from here
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath true
            }
        }
        //Addition part so far
    }
    ~~~~~Omission~~~~~
}

> Eliminate!

Run-time bugs

The keyboard starts up without permission at the time of activity transition

https://codeday.me/jp/qa/20190205/219782.html https://developer.android.com/reference/android/view/WindowManager.LayoutParams#SOFT_INPUT_STATE_ALWAYS_HIDDEN In the onCreate method of the activity you don't want to launch

this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Is additionally resolved

By the way, `` `setSoftInputMode``` can specify the behavior of the soft keyboard for the specified Window.

WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN prevents the keyboard from rising when the focus is on



## Notification does not disappear even if the application is started / transition from push notification
 The cause was that there was no process to turn off the notification in the first place
 In FCM in onMessage

if(prefs.getInt("push_flg", 1)==1){ NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, splash.class), 0); notification.setLatestEventInfo(this, "Favorite character string", str, contentIntent); mNotificationManager.notify(1, notification); }

 There should be processing like.

#### **`mNotificationManager.notify(1, notification);The first argument of is the notification ID (int type).`**
```notify(1, notification);The first argument of is the notification ID (int type).

 When erasing, specify this and anywhere

//Turn off when notified NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.cancel(1);

 OK
 This time, I installed it right after the start of onCreate on the top page.

 By the way, the above method setLatestEventInfo () has been deprecated and removed from API level 23.
 The recommendation is to use NotificationCompat

if(prefs.getInt("push_flg", 1)==1){ NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, splash.class), 0);

      NotificationCompat.Builder mBuilder =
              new NotificationCompat.Builder(this)
              .setSmallIcon(R.drawable.icon)          //Notification icon
              .setContentTitle("Notification title")           //Notification title
              .setContentText(str)                    //Notification body
              .setContentIntent(contentIntent);       //Where to transition when tapped
      
      mNotificationManager.notify(1, mBuilder.build());  //Registration

}

 I use it like that.
 further

mBuilder.setAutocancel(true);

 You can also delete the notification when you tap it.
 You can also use the above `` `mNotificationManager.cancel ()` ``, so you can delete it anywhere.

install_failed_no_matching_abis res =- 113
 Occurs when trying to run in the emulator
https://stackoverflow.com/questions/36414219/install-failed-no-matching-abis-failed-to-extract-native-libraries-res-113
 Modify app / build.gradle for reference

android { ~~~Omission~~~~

//add to
splits {
    abi {
        enable true
        reset()
        include 'x86', 'armeabi-v7a', 'x86_64'
        universalApk true
    }
}
~~~Omission~~~~

}

 Solved with
 By the way, if you do this, there is a possibility that inconvenience will occur in the release build, so if it does not occur in the actual machine, it is necessary to remove the above only in the release build.
 To be honest, it's a hassle, so is there a better way ...

android.os.NetworkOnMainThreadException
 Error when skipping a specific API

https://shirusu-ni-tarazu.hatenablog.jp/entry/2013/01/20/033030
http://shiro-16.hatenablog.com/entry/2014/03/25/004856
 According to the specifications from android studio 3.x, you should not try to communicate from the main thread
 Fixed to skip from another thread

new Thread(new Runnable() { @Override public void run() { //API skip method } }).start();

 Feeling

android studio Only the original thread that created a view hierarchy can touch its views.
 This is the opposite of the above, and if you try to change the view from other than the main thread, an error will occur.

 Since it was a part that could not be done from the main thread in the place related to the above error
http://accelebiz.hatenablog.com/entry/2016/09/01/061934
 Avoid using `handler.post` for reference
 However, if you put it in handler.post up to the point where you are communicating, the above `NetworkOnMainThreadException` will occur this time, so be careful

requestFeature() must be called before adding content
https://stackoverflow.com/questions/4250149/requestfeature-must-be-called-before-adding-content
 Corresponding to reference

requestWindowFeature(Window.FEATURE_NO_TITLE);

 I was using, so I moved this right after super ()
 > Resolved, but may be version dependent. Investigation required

## The version judgment of the terminal is strange
 Even though it's Oreo, it doesn't judge that ...
 As long as I stop at the breakpoint, I feel that the result of ʻisAtLeast0 ()` is strange.
https://qiita.com/nukka123/items/60a942d054c17c9610ab
 As I said in, there seems to be a bug in the method itself
 Try to specify 26.0.1 which is the latest of > 26.0. +
 (The version is
https://dl.google.com/dl/android/maven2/index.html
 Confirm with. )
>`Error:(52, 13) Failed to resolve: com.android.support:support-v4:26.0.1`
>https://qiita.com/meru_h/items/f198a300d41e0c59aea4
 Same correspondence as
 > Elimination

## http communication fails from android ver.9
https://backport.net/blog/2018/12/27/how_to_allow_http_on_android_9/
http://blog.riskfinder.co.jp/2016/03/network-security-configuration-android-n.html
 According to the above article, it will be played if you communicate with http from android 9.0, but if you explicitly allow it, it will pass.
 The following support is deprecated because it is preferable to use blunt https ...
 This time it corresponds by creating NetworkSecurityConfig.xml


#### **`network_security_config.xml`**
```xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">hoge.com</domain>
    </domain-config>
</network-security-config>

> to androidManifest

   <application
        (abridgement)
        android:networkSecurityConfig="@xml/network_security_config"
        >

Add, check the operation and finish

Other

Logcat does not come out

Occurs in android studio 2.3 It's embarrassing in a very basic way, but a note for self-discipline ...

Not that it is not output, it does not exist in the tab at the bottom, and the window itself can not be output Because the window just doesn't appear http://aws-mobile-development.hatenablog.com/entry/2016/11/06/065030#2Logcat%E8%A1%A8%E7%A4%BA%E6%96%B9%E6%B3%95 Displayed with. Solution. Note that a window will be added with the name "Android Monitor" instead of "logcat"

waiting for target device to come online keeps appearing and cannot be executed

http://b0npu.hatenablog.com/entry/2018/04/07/084709 Try cold boot now > There is no item itself >https://stackoverflow.com/questions/42757928/waiting-for-target-device-to-come-online-in-android-studio-2-3 Try updating sdk tools > No change

Try another version once (the emulator at this time is sdk19) 26 worked > I can't try again at 19 Delete 19 once and reinsert it to see I got a message that performance may drop if I do not put it on x86, so I will try putting it on x86 > Finally connected ... It seems that the source to put in is different from other images

In another case, it was fixed by restarting android studio.

Recommended Posts

Problems with android studio development series
Face recognition app with OpenCV + Android Studio
24 hours struggling with Android development, Java Optional
Android Development App_Preparation
Riot (chat app) development (settings) in Android Studio
Android Studio development for the first time (for beginners)
Compatible with Android 10 (API 29)
Android development link summary
Experienced Java users get started with Android application development
Plugin development with ImageJ
[Rails] Development with MySQL
Android application development preparation 7/15
Notes in Android studio
Defeating Android Studio Part 3-6
Build Java program development environment with Visual Studio Code
Recent problems with rbenv
Defeating Android Studio Part 1 & Part 2
Android development reference site
How to take a screenshot with the Android Studio emulator
Use Java included with Android Studio to build React Native
How to make an app using Tensorflow with Android Studio
Build WebAPP development environment with Java + Spring with Visual Studio Code
Android app personal development kickoff
Solve Google problems with Ruby
Introduction to Android application development
ROS app development on Android
Android development ~ Screen transition (intent) ~
I tried to take a look at the flow of Android development environment construction with Android Studio
[Ruby] REPL-driven development with pry
Source to display character array with numberPicker in Android studio (Java)
Introduction to Android App Development 1 Installing JDK and Android Studio for mac