質問編集履歴

1

記載するソースコードが間違っていたので修正

2022/09/21 03:27

投稿

rin9
rin9

スコア0

test CHANGED
File without changes
test CHANGED
@@ -78,70 +78,55 @@
78
78
 
79
79
  ### build.gradle (:app)
80
80
  ```gradle
81
+ plugins {
81
- package com.example.test_application
82
+ id 'com.android.application'
83
+ id 'org.jetbrains.kotlin.android'
84
+ }
82
85
 
83
- import android.os.Bundle
86
+ android {
84
- import androidx.fragment.app.Fragment
85
- import android.view.LayoutInflater
86
- import android.view.View
87
- import android.view.ViewGroup
88
- import androidx.navigation.fragment.findNavController
89
- import com.example.test_application.databinding.FragmentFirstBinding
87
+ namespace 'com.example.test_application'
90
- import java.io.IOException
91
- import okhttp3.*
88
+ compileSdk 32
92
89
 
93
- /**
90
+ defaultConfig {
94
- * A simple [Fragment] subclass as the default destination in the navigation.
91
+ applicationId "com.example.test_application"
95
- */
92
+ minSdk 30
93
+ targetSdk 32
94
+ versionCode 1
96
- class FirstFragment : Fragment() {
95
+ versionName "1.0"
97
96
 
98
- private var _binding: FragmentFirstBinding? = null
99
-
100
- // This property is only valid between onCreateView and
101
- // onDestroyView.
102
- private val binding get() = _binding!!
103
-
104
- override fun onCreateView(
105
- inflater: LayoutInflater, container: ViewGroup?,
106
- savedInstanceState: Bundle?
107
- ): View? {
108
-
109
- _binding = FragmentFirstBinding.inflate(inflater, container, false)
97
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
110
- return binding.root
111
-
112
98
  }
113
99
 
100
+ buildTypes {
101
+ release {
102
+ minifyEnabled false
114
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
103
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
115
- super.onViewCreated(view, savedInstanceState)
116
-
117
- binding.buttonFirst.setOnClickListener {
118
- findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment)
119
104
  }
120
105
  }
121
-
122
- private val client = OkHttpClient.Builder()
123
- .connectTimeout(CONNECTION_TIMEOUT_MILLISECONDS.toLong(), TimeUnit.MILLISECONDS)
124
- .readTimeout(READ_TIMEOUT_MILLISECONDS.toLong(), TimeUnit.MILLISECONDS)
125
- .build()
126
-
127
- fun startGetRequest() {
128
- val request = Request.Builder()
129
- .utl("https://482f.net/api/regalias")
130
- .build()
131
- client.newCall(request).enqueue(object: Callback {
132
- fun onResponse(call: Call, response: Response) {
133
- val responseBody = response.body?.string().orEmpty()
134
- Log.println(responseBody)
106
+ compileOptions {
135
- }
136
- fun onFailure(call: Call, e: IOException) {
107
+ sourceCompatibility JavaVersion.VERSION_1_8
137
- Log.e("Error", e.toString())
108
+ targetCompatibility JavaVersion.VERSION_1_8
138
- }
139
- })
140
109
  }
141
-
110
+ kotlinOptions {
142
- override fun onDestroyView() {
111
+ jvmTarget = '1.8'
112
+ }
143
- super.onDestroyView()
113
+ buildFeatures {
144
- _binding = null
114
+ viewBinding true
145
115
  }
146
116
  }
117
+
118
+ dependencies {
119
+
120
+ implementation 'androidx.core:core-ktx:1.7.0'
121
+ implementation 'androidx.appcompat:appcompat:1.4.1'
122
+ implementation 'com.google.android.material:material:1.5.0'
123
+ implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
124
+ implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
125
+ implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
126
+ testImplementation 'junit:junit:4.13.2'
127
+ androidTestImplementation 'androidx.test.ext:junit:1.1.3'
128
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
129
+
130
+ implementation 'com.squareup.okhttp3:okhttp:4.10.0'
131
+ }
147
132
  ```