java- Android Studio [ClassNotFoundException] - android

I got problem when change name packages in android studio,
first i use some open source project, then when i want to change the previous packages some of function cant be used, the error message is "ClassNotFoundException:yuku.kpri.model.Song" even thoughni already change packages "yuku" to "buna" and all packages that related to "yuku" change to "buna" and also packages "yuku.kpri.model.Song" changes to "buna.kpri.model.Song" but the code still run to yuku.kpri.model.Song,
I already try many solution like
Close/Unselect Compact Empty Middle Packages ,Then right click your package and rename it. Here
Clean Project
Rebuild Project
change the applicationId Here
Error Message when try to use the function
Here
Help me to solve this problem, what i miss and my mistake...
im looking for your answer

One thing you could try is selecting File --> Invalidate Caches/Restart, sometimes it works magic.

This could be a Proguard issue.
Try to set "minifyEnabled false" for both Release & Debug build types in your projects build.gradle file :
buildTypes {
debug {
minifyEnabled false
}
release {
minifyEnabled false
}
}
If this works, you should exclude the class in the proguard-ruls.pro file.

Related

Android debugSymbolLevel = { SYMBOL_TABLE | FULL } not working

I want to upload an Android app with debug symbols to Google Play Console in order to have detailed crash logs for my C++ code.
So I followed the steps here and added this line:
android.buildTypes.release.ndk.debugSymbolLevel = 'FULL'
At the top of my Gradle file just below the 'apply plugin:' lines (in the Gradle at :app level)
I also tried to add:
ndk {
debugSymbolLevel 'FULL'
}
in: buildTypes { release{ here!!! }}
but doesn't work.
I still get the following message in the Google Play Console when I upload my app:
This App Bundle contains native code, and you've not uploaded debug
symbols. We recommend you upload a symbol file to make your crashes
and ANRs easier to analyze and debug.
The problem is mentioned here but not solved.
Anybody found a workaround?
Thanks.
In my case my build.gradle script already had a buildTypes block and in that block I could set up the ndk.debugSymbolLevel config option, an image say more than thousand words, hope it can help you
image of my build.gradle script

Failed to Generate Signed Apk - An organization slug is required (provide with --org)

After setting up the Sentry.io error tracking I get this error when I try to Generate Signed Apk:
Java Compiler
error: An organization slug is required (provide with --org)
Click on this image and open it to see more details:
I cannot understand anything from this one:
Process 'command
'/var/folders/j4/_fzm1rks3tsc2h3j4l2qbq4w0000gn/T/.sentry-cli1369818638611304938.exe'
' finished with non-zero exit value 1
This is the file address that was raised in error:
How can I solve this problem and Generate Signed Apk?
The docs are not a bit clear, though its mentioned but easy to miss it. There are two different sentry.properties required here.
Please note the sentry.properties in your project root that configures sentry-cli is different than the one you include in your application resources to configure the Sentry SDK at runtime (as seen in the configuration documentation).
You need to have another sentry.properties file in the project root with
defaults.project=your-project
defaults.org=your-org
auth.token=YOUR_AUTH_TOKEN
and the runtime sentry.properties with DSN values, etc can be placed in app/src/main/resources directory(create resource directory if required)
Config Docs
You need to upload the Proguard mapping file to the sentry server.
create a file in the root project folder and set name sentry.properties.
defaults.url=https://sentry.io
defaults.org=TEST
defaults.project=TEST_DEV
auth.token=TOKEN
replace TEST, TEST_DEV, and TOKEN.
you can get TOKEN from https://sentry.io/api
if you are use custom sentry server, replace https://sentry.io to your server adddress.
and change file build.gradle
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'io.sentry:sentry-android-gradle-plugin:1.7.27'
}
}
and
apply plugin: 'com.android.application'
apply plugin: 'io.sentry.android.gradle'
...
sentry {
autoProguardConfig true
autoUpload true
}
android {
...
}
dependencies {
...
implementation 'io.sentry:sentry-android:1.7.27'
implementation 'org.slf4j:slf4j-nop:1.7.25'
...
}
When you enable Proguard minification, symbols are uploaded to Sentry.
This upload is done via the sentry-cli, which is throwing the error. The error says the CLI doesn't know which project within Sentry to associate your symbols with.
You need to make sure to go through the gradle integration in the docs.
Specifically:
defaults.project=airflow
defaults.org=sentry
auth.token=YOUR_AUTH_TOKEN
Alternatively you can use sentry-cli directly to upload symbols, although the gradle integration is advised.
For ReactNative/iOS, if you have such errors check that you put sentry.properties file in iOS folder
I also stranded here whilst trying to figure what was going wrong with my sentry source map uploads (not on android, but for web with a similar error). To debug my events that weren't matched, I was using the sentry-cli like so;
So I was searching how I could add the organization slug to my source map uploads. But this error wasn't about the event, but for using the explain CLI functionality itself!!! Which confused me.
I had to pass additional parameters to the CLI script to get the actual problem with the event;
Maybe this will help someone else who also skipped over the docs 😅
instead of making
minifyEnabled false
Just add these rules to proguard rules file and keep minifyEnabled true
#sentry
-keepattributes LineNumberTable,SourceFile
-dontwarn org.slf4j.**
-dontwarn javax.**
-keep class io.sentry.event.Event { *; }
That solved my issue without disabling minification
IT IS NOT A REAL ANSWER But it can solve our problem in the short term by setting false value to minifyEnabled.
app/build.gradle:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
but it added 1.3MB to the size my of Apk file.
Please let me know if anyone has a different better solution.

Crashlytics for Android: Disable automatic upload of mapping file via Gradle build

I'd like to use crashlytics in our app, but I'm not allowed to upload it's proguard mapping file anywhere to the outside world (company policy). Is it possible to use Crashlytics but with obfuscated stacktraces?
In io.fabric plugin's docs I've found this option:
ext.enableCrashlytics = false
But it disables whole reporting, so that's not what I want.
I have added this at the end of app gradle file:
tasks.whenTaskAdded {task ->
if(task.name.toLowerCase().contains("crashlytics")) {
task.enabled = false
}
}
Build log:
> Task :app:crashlyticsStoreDeobsDebug SKIPPED
> Task :app:crashlyticsUploadDeobsDebug SKIPPED
Please note that this disables all crashlytics related tasks. Uploading proguard mapping file by default is some kind of misunderstanding. It is like uploading private key and its password. This file should only be stored in your vault. So I guess it is better to completely disable all their task by default :)
I am just wondering why this is not a big issue for developers.
They have everything planned ! ;-) According to this link : "Crashlytics automatically de-obfuscates stack traces for your reports", so you shouldn't have to worry about it.
Simply obfuscate your app with ProGuard, don't forget to update ProGuard rules to avoid unexpected crashes with release app, and it should be ok !
(help page is about Eclipse, but I used Crashlytics with Android Studio just some days ago, and it works fine too)
EDIT 1 : and according to the very end of this second link, Crashlytics automatically upload mapping file during build. It seems you aren't able to disable this.
EDIT 2 : maybe if you use Ant, you would be able to customize (at least a bit) build rules, thanks to crashlytics_build.xml and crashlytics_build_base.xml files. But I'm not used to Ant, and even there, when I read file, it seems the "mapping files auto upload" can't be disabled. :-/
try disable task 'crashlyticsUploadDeobs':
afterEvaluate {
for (Task task : project.tasks.matching { it.name.startsWith('crashlyticsUploadDeobs') }) {
task.enabled = false
}}
Add to app build Gradle file
firebaseCrashlytics {
mappingFileUploadEnabled false
}
https://firebase.google.com/docs/crashlytics/get-deobfuscated-reports?platform=android
if you does not have internet connect at that time what will happened mapping will upload to crashlytics or not.

Unable to open debugger port : java.net.SocketException “Socket closed”

I'm using Android Studio, with multiple flavors using Gradle, each with a Debug and Release type, organized as described here, on the bottom half.When I try to start the debugger, I get this error:
Error running androidRecover [installAppDebug]: Unable to open debugger port : java.net.SocketException "Socket closed
I'm also unable to attach the debugger to my device once it's running (it only displays the name of my phone, not the app).
All 3 flavors install on my phone just fine. I just can't get it to let me debug them. I also tested attaching the debugger on a Nexus tablet, and I got the same result.
It's not Gradle specifically as a whole because I can run other Gradle-based apps and attach the debugger just fine so I wonder if it's something with how I've setup my Gradle project and settings.
Here's my build.gradle:
apply plugin: 'android'
apply from: 'signing.gradle'
android {
compileSdkVersion 19
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile
('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
flav1 {
packageName "com.ex.flav1"
versionCode 32
versionName "1.0.5"
signingConfig signingConfigs.flav1
}
flav2 {
packageName "com.ex.flav2"
versionCode 33
versionName "1.0.6"
signingConfig signingConfigs.flav2
}
flav3 {
packageName "com.ex.flav3"
versionCode 27
versionName "1.0.0"
signingConfig signingConfigs.flav3
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/httpmime-4.2.5.jar')
}
I really have no idea what else to try. Android Studio is completely up-to-date. I've restarted Android Studio, my phone, and my computer.
Also, last week I was having this problem, but it was a specific socket that was blocked, from trying to run the emulator and my phone at the same time. I also noticed I had multiple Gradle processes running, because it wasn't killing them on its own, which I often had to kill Android Studio to kill them. Once that was fixed, it was working off and on.
Let me know if you need any other info.
Thanks,
Devin
Edit I finally know why #hasanaydogar's answer works and why it probably would have solved my problem if we had known it then. See my 2nd comment on it to know why, but in short, you have to select in that dropdown the name that matches your app's root directory.
Just Click the button (left side the RUN button).
Select Android. Then Run.
It will connect to your device.
And dont forget to change build variant
I finally understand why I was getting that error so I'm going to explain how I Debug now. Note that I use Gradle (build multiple apk's using the same code), which might influence some how you use the third part of this answer.
For these to work, in the dropdown next to the debug (icon in #1) and run buttons in the top toolbar, you have to have the one selected with the following icon next to it because that's the name of the root directory of your app where all your code lives:
To start debugging from the beginning, I run the app in Debug mode from the start, using this button in your toolbar:
To attach the debugger to the app when it's already running as #scottyab mentioned, I click the Attach Debugger button in your toolbar:
To run the release version of my app in debug mode, I've started changing my strings in the Debug version of strings.xml in the file path myApp/src/appNameDebug(verses appNameRelease)/res/values/strings.xml, more easily seen here, on the bottom half. When I say change, I really mean that I have two versions of all the strings (3 in my case) necessary to change from using the debug server to using the release server. It might not be completely kosher, but it takes about 5 seconds to go the file, and hold down Cmd+/ and uncomment and comment all of the appropriate lines.
My Release version is just there for when I'm ready to build an apk for release.
Doing things in this way has eliminated that error popping up anymore. I think the Release version is just not made for debugging, and I haven't found an easy way to turn the debug flags on when in Release mode.
I managed to get this working by attaching the debugger after a build see Unable to open debugger port : java.net.SocketException "Socket closed"
I managed to get rid of this problem by killing & restart the adb process,hope this would help :]
I have solved this question with reference to the following SO Answer
The "Select Run/Debug Configuration" button in android studio 2.3.2
Change the Debug type to Native

Android studio omits breakpoints

When I'm trying to debug application using android studio, I set some breakpoints in the IDE and after starting the debugger I've got an info on every single one breakpoint (in the baloon):
Warning : No executable code found at line ...
It looks like the message appears when the application reaches first BP.
Just to be clear - I have executable code in those lines like String s = "asd";
In my case a Build - Clean Project did help.
set the minifyEnabled to false:
From the project section select the project
Right click on project and click open module settings
select the module you are running and from Build Type set the Minify Enabled to false
Try to insert the next snippet code into the android{} block on the app build.gradle file:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false //<---- THIS FIX THE PROBLEM
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'pro
guard-rules.pro'
}
}
Do you debug on device or on emulator? If device then try to switch back to Dalvik from ART
The first line breakpoint works only
Responding to user3167086's post -
I had the same problem with the breakpoints not working in the middle of a method. One line of code was fine, and the break point icon had a "check mark" in it, but the next point had an "x" in the icon and gave the warring of "no executable code". I checked the Project Structure and the Build Type had already defaulted to "false", but I set it to false again and clicked OK.
For those using Android Studio 1.5 like I am, the complete procedure - using the main menu - is to
select File -> Project Structure.
Then select your "App" module on the left, and then the "Build Types" tab across the top.
Make sure you have "Debug" selected and not "release" on the left (you should see this at the top of the right hand column too) and then set Minify Enabled to FALSE.
Make sure that you use a "Debug" build variant - otherwise breakpoints don't work.
I saw this error message in a pop-up over the dreaded breakpoint with an X in it, in Android Studio's "stable" version 2.1.2 (Gradle: 2.10, Android Plugin: 2.1.2), and the fix was to simply hit the red 'stop' button on the current run session in Android Studio.
I have no idea how the current run session could interfere with setting a break point in source (I have everything under 'Instant Run' unchecked), but this worked for some reason.
For the future:
In my case ALL lines of code were unavailable for debugger. Solution for my problem was disabling jack to avoid creation of intermediate code.
These lines in my gradle.build were to blame:
defaultConfig {
jackOptions {
enabled true
}
}
I turned jack options on several months earlier and then switched back to Java7 forgetting about how my application works. No suprisde Android Studio couldn't find matching code.
I hope it will help.

Categories

Resources