I am building a weather displaying android application with the api of openweather.org api key.
I have written some basic logic to display the weather details of a related city when the user searches the city
So the error i am facing is as displayed as follows,
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.openweather, PID: 2966
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.openweather-SX-bmUO1B6_TZYTWtbjZGQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.openweather-SX-bmUO1B6_TZYTWtbjZGQ==/lib/arm64, /system/lib64]]] couldn't find "libkeys.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:1067)
at java.lang.Runtime.loadLibrary0(Runtime.java:1007)
at java.lang.System.loadLibrary(System.java:1667)
at com.example.openweather.Retrofit.ApiClient.<clinit>(ApiClient.java:10)
at com.example.openweather.Retrofit.ApiClient.getClient(ApiClient.java:21)
at com.example.openweather.MainActivity.getWeatherData(MainActivity.java:52)
at com.example.openweather.MainActivity.access$000(MainActivity.java:19)
at com.example.openweather.MainActivity$1.onClick(MainActivity.java:44)
at android.view.View.performClick(View.java:7870)
at android.view.View.performClickInternal(View.java:7839)
at android.view.View.access$3600(View.java:886)
at android.view.View$PerformClick.run(View.java:29363)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7948)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
So I have 4 classes and an interface to this project which are as follows,
The Main Activity
package com.example.openweather;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.openweather.Retrofit.ApiClient;
import com.example.openweather.Retrofit.ApiInterface;
import com.example.openweather.Retrofit.Example;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class MainActivity extends AppCompatActivity {
ImageView search;
TextView tempText,
descText,
humidityText;
EditText textField;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
search = findViewById(R.id.search);
tempText = findViewById(R.id.tempText);
descText = findViewById(R.id.descText);
humidityText = findViewById(R.id.humidityText);
textField = findViewById(R.id.textField);
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getWeatherData(textField.getText().toString().trim());
}
});
}
private void getWeatherData(String name) {
ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
Call<Example> call = apiInterface.getWeatherData(name);
call.enqueue(new Callback<Example>() {
@Override
public void onResponse(Call<Example> call, Response<Example> response) {
try {
tempText.setText("Temp" + " " + response.body().getMain().getTemp() + " C");
descText.setText("Feels Like" + " " + response.body().getMain().getFeels_like());
humidityText.setText("Humidity" + " " + response.body().getMain().getHumidity());
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Call<Example> call, Throwable t) {
}
});
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
}
The ApiInterface
package com.example.openweather.Retrofit;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;
public interface ApiInterface {
@GET("https://api.openweathermap.org/data/2.5/weather?appid=1ebf50976c7bdea4db9a208956569a84&units=metric")
Call<Example> getWeatherData(@Query("q") String name);
}
The ApiClient Java Class
package com.example.openweather.Retrofit;
import android.util.Base64;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class ApiClient {
static {
System.loadLibrary("keys");
}
public native static String getApi();
private static Retrofit retrofit = null;
public static String APIKEY = new String(Base64.decode(getApi(), Base64.DEFAULT));
public static Retrofit getClient(){
if (retrofit == null){
retrofit = new Retrofit.Builder()
.baseUrl("https://api.openweathermap.org/data/2.5/")
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
The Example Java Class (Example.java)
package com.example.openweather.Retrofit;
import com.google.gson.annotations.SerializedName;
public class Example {
@SerializedName("main")
private Main main;
public Main getMain() {
return main;
}
public void setMain(Main main) {
this.main = main;
}
}
The Main Java Class (Main.java)
package com.example.openweather.Retrofit;
import com.google.gson.annotations.SerializedName;
public class Main {
@SerializedName("temp")
String temp;
@SerializedName("humidity")
String humidity;
@SerializedName("feels_like")
String feels_like;
public String getTemp() {
return temp;
}
public void setTemp(String temp) {
this.temp = temp;
}
public String getHumidity() {
return humidity;
}
public void setHumidity(String humidity) {
this.humidity = humidity;
}
public String getFeels_like() {
return feels_like;
}
public void setFeels_like(String feels_like) {
this.feels_like = feels_like;
}
}
The Module Build Gradle
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.openweather"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
}
I have tried some ways to overcome the issue but have failed.
Hope to get a solituon for this
What I have tried:
Have tried different solutions by removing the retrofit dependencies and readding them back to project and altering the api key and so on, but nothing seems to be working