Unable to access companion object used in kotlin class after enabling proguard
I have a Kotlin class with some variables in companion object. After enabling proguard, The variables are not getting accessed.
class Test{
......
companion object {
const val USER_NAME = "user_name"
.....
}
.....
}
Proguard rules include:-
-keep class kotlin.** { *; }
-keep class kotlin.Metadata { *; }
-dontwarn kotlin.**
-keepclassmembers class **$WhenMappings {
<fields>;
}
-keepclassmembers class kotlin.Metadata {
public <fields>;
public <methods>;
}
-keepclassmembers class * {
static final % *;
static final java.lang.String *;
}
kotlin proguard
|
show 1 more comment
I have a Kotlin class with some variables in companion object. After enabling proguard, The variables are not getting accessed.
class Test{
......
companion object {
const val USER_NAME = "user_name"
.....
}
.....
}
Proguard rules include:-
-keep class kotlin.** { *; }
-keep class kotlin.Metadata { *; }
-dontwarn kotlin.**
-keepclassmembers class **$WhenMappings {
<fields>;
}
-keepclassmembers class kotlin.Metadata {
public <fields>;
public <methods>;
}
-keepclassmembers class * {
static final % *;
static final java.lang.String *;
}
kotlin proguard
Are you getting a runtime error, if so please post the error and stack trace as part of your question.
– Jayson Minard
Nov 28 '18 at 17:50
No it is not run time error, It is a compile time error. While trying to build my project I am getting error as Unresolved reference : USER_NAME.
– Surbhi
Nov 30 '18 at 5:46
Would annotating with@JvmStaticnot help in this case?
– Jan Vladimir Mostert
Nov 30 '18 at 6:40
I have tried adding that but I guess we need to add some rule in proguard related to @JvmStatic in this case. I tried finding it but couldn't.
– Surbhi
Dec 1 '18 at 5:35
What does the code look like that is referencing the variable, and what is the exact error message from the compiler, these are important details to add to your question.
– Jayson Minard
Dec 1 '18 at 22:26
|
show 1 more comment
I have a Kotlin class with some variables in companion object. After enabling proguard, The variables are not getting accessed.
class Test{
......
companion object {
const val USER_NAME = "user_name"
.....
}
.....
}
Proguard rules include:-
-keep class kotlin.** { *; }
-keep class kotlin.Metadata { *; }
-dontwarn kotlin.**
-keepclassmembers class **$WhenMappings {
<fields>;
}
-keepclassmembers class kotlin.Metadata {
public <fields>;
public <methods>;
}
-keepclassmembers class * {
static final % *;
static final java.lang.String *;
}
kotlin proguard
I have a Kotlin class with some variables in companion object. After enabling proguard, The variables are not getting accessed.
class Test{
......
companion object {
const val USER_NAME = "user_name"
.....
}
.....
}
Proguard rules include:-
-keep class kotlin.** { *; }
-keep class kotlin.Metadata { *; }
-dontwarn kotlin.**
-keepclassmembers class **$WhenMappings {
<fields>;
}
-keepclassmembers class kotlin.Metadata {
public <fields>;
public <methods>;
}
-keepclassmembers class * {
static final % *;
static final java.lang.String *;
}
kotlin proguard
kotlin proguard
edited Nov 30 '18 at 5:46
Surbhi
asked Nov 28 '18 at 13:56
SurbhiSurbhi
386314
386314
Are you getting a runtime error, if so please post the error and stack trace as part of your question.
– Jayson Minard
Nov 28 '18 at 17:50
No it is not run time error, It is a compile time error. While trying to build my project I am getting error as Unresolved reference : USER_NAME.
– Surbhi
Nov 30 '18 at 5:46
Would annotating with@JvmStaticnot help in this case?
– Jan Vladimir Mostert
Nov 30 '18 at 6:40
I have tried adding that but I guess we need to add some rule in proguard related to @JvmStatic in this case. I tried finding it but couldn't.
– Surbhi
Dec 1 '18 at 5:35
What does the code look like that is referencing the variable, and what is the exact error message from the compiler, these are important details to add to your question.
– Jayson Minard
Dec 1 '18 at 22:26
|
show 1 more comment
Are you getting a runtime error, if so please post the error and stack trace as part of your question.
– Jayson Minard
Nov 28 '18 at 17:50
No it is not run time error, It is a compile time error. While trying to build my project I am getting error as Unresolved reference : USER_NAME.
– Surbhi
Nov 30 '18 at 5:46
Would annotating with@JvmStaticnot help in this case?
– Jan Vladimir Mostert
Nov 30 '18 at 6:40
I have tried adding that but I guess we need to add some rule in proguard related to @JvmStatic in this case. I tried finding it but couldn't.
– Surbhi
Dec 1 '18 at 5:35
What does the code look like that is referencing the variable, and what is the exact error message from the compiler, these are important details to add to your question.
– Jayson Minard
Dec 1 '18 at 22:26
Are you getting a runtime error, if so please post the error and stack trace as part of your question.
– Jayson Minard
Nov 28 '18 at 17:50
Are you getting a runtime error, if so please post the error and stack trace as part of your question.
– Jayson Minard
Nov 28 '18 at 17:50
No it is not run time error, It is a compile time error. While trying to build my project I am getting error as Unresolved reference : USER_NAME.
– Surbhi
Nov 30 '18 at 5:46
No it is not run time error, It is a compile time error. While trying to build my project I am getting error as Unresolved reference : USER_NAME.
– Surbhi
Nov 30 '18 at 5:46
Would annotating with
@JvmStatic not help in this case?– Jan Vladimir Mostert
Nov 30 '18 at 6:40
Would annotating with
@JvmStatic not help in this case?– Jan Vladimir Mostert
Nov 30 '18 at 6:40
I have tried adding that but I guess we need to add some rule in proguard related to @JvmStatic in this case. I tried finding it but couldn't.
– Surbhi
Dec 1 '18 at 5:35
I have tried adding that but I guess we need to add some rule in proguard related to @JvmStatic in this case. I tried finding it but couldn't.
– Surbhi
Dec 1 '18 at 5:35
What does the code look like that is referencing the variable, and what is the exact error message from the compiler, these are important details to add to your question.
– Jayson Minard
Dec 1 '18 at 22:26
What does the code look like that is referencing the variable, and what is the exact error message from the compiler, these are important details to add to your question.
– Jayson Minard
Dec 1 '18 at 22:26
|
show 1 more comment
1 Answer
1
active
oldest
votes
Problem resolved using @Keep before companion object
class Test{
......
@Keep companion object {
const val USER_NAME = "user_name"
.....
}
.....
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53521118%2funable-to-access-companion-object-used-in-kotlin-class-after-enabling-proguard%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Problem resolved using @Keep before companion object
class Test{
......
@Keep companion object {
const val USER_NAME = "user_name"
.....
}
.....
}
add a comment |
Problem resolved using @Keep before companion object
class Test{
......
@Keep companion object {
const val USER_NAME = "user_name"
.....
}
.....
}
add a comment |
Problem resolved using @Keep before companion object
class Test{
......
@Keep companion object {
const val USER_NAME = "user_name"
.....
}
.....
}
Problem resolved using @Keep before companion object
class Test{
......
@Keep companion object {
const val USER_NAME = "user_name"
.....
}
.....
}
answered Dec 20 '18 at 6:44
SurbhiSurbhi
386314
386314
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53521118%2funable-to-access-companion-object-used-in-kotlin-class-after-enabling-proguard%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you getting a runtime error, if so please post the error and stack trace as part of your question.
– Jayson Minard
Nov 28 '18 at 17:50
No it is not run time error, It is a compile time error. While trying to build my project I am getting error as Unresolved reference : USER_NAME.
– Surbhi
Nov 30 '18 at 5:46
Would annotating with
@JvmStaticnot help in this case?– Jan Vladimir Mostert
Nov 30 '18 at 6:40
I have tried adding that but I guess we need to add some rule in proguard related to @JvmStatic in this case. I tried finding it but couldn't.
– Surbhi
Dec 1 '18 at 5:35
What does the code look like that is referencing the variable, and what is the exact error message from the compiler, these are important details to add to your question.
– Jayson Minard
Dec 1 '18 at 22:26