android:theme="@style/apptheme",android studio - setTheme(R.style.AppTheme) not working when creatin...

I display a splash screen on my Android app by using a theme for loading. In the MainActivity I change the theme using setTheme. It works when I build the app from Android Studio on the emulator (it compiles and runs). When I try to build an APK using Build->Build APKs, I get an error.

E:\AndroidStudioProjects\gb\feature\src\main\java\com\zwsi\gb\feature\MainActivity.kt: (25, 20): Unresolved reference: style

What is different when building APK vs. building an app?

AndroidManifest.xml

package="com.perrochon.gb">

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/AppTheme.Launcher">

android:name="aia-compat-api-min-version"

android:value="1"/>

styles.xml

@drawable/app_background

@drawable/launch_background

MainActivity.kt

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

setTheme(R.style.AppTheme) // TODO switch back from the Launcher Theme, but this won't compile to APK

// setTheme(R.style.AppTheme) works in Android Studio -> Emulator, but not when building APKs. Error is

// E:\AndroidStudioProjects\gb\feature\src\main\java\com\zwsi\gb\feature\MainActivity.kt: (25, 20): Unresolved reference: style

super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

Edit: Adding build gradle files. I haven't really done anything with the gradel build files, they are the way Android Studio set them up.

build.gradle from gb

buildscript {

ext.kotlin_version = '1.2.71'

repositories {

google()

jcenter()

}

dependencies {

classpath 'com.android.tools.build:gradle:3.2.1'

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong

// in the individual module build.gradle files

}

}

allprojects {

repositories {

google()

jcenter()

}

}

task clean(type: Delete) {

delete rootProject.buildDir

}

build.gradle from gb\feature

apply plugin: 'com.android.feature'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {

compileSdkVersion 28

defaultConfig {

minSdkVersion 15

targetSdkVersion 28

versionCode 1

versionName "1.0"

testInstrumentationRunner

"android.support.test.runner.AndroidJUnitRunner"

}

}

dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation project(':base')

implementation project(':gblib')

testImplementation 'junit:junit:4.12'

androidTestImplementation 'com.android.support.test:runner:1.0.2'

androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

build.gradle from gb\base

apply plugin: 'com.android.feature'

android {

compileSdkVersion 28

baseFeature true

defaultConfig {

minSdkVersion 15

targetSdkVersion 28

versionCode 1

versionName "1.0"

}

buildTypes {

release {

minifyEnabled false

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

}

}

}

dependencies {

api 'com.android.support:appcompat-v7:28.0.0'

api 'com.android.support.constraint:constraint-layout:1.1.3'

api 'com.android.support:support-v4:28.0.0'

application project(':app')

feature project(':feature')

}

build.gradle from gb\app

apply plugin: 'com.android.application'

android {

compileSdkVersion 28

defaultConfig {

applicationId "com.zwsi.gb.app"

minSdkVersion 15

targetSdkVersion 28

versionCode 1

versionName "1.0"

}

buildTypes {

release {

minifyEnabled false

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

}

}

}

dependencies {

implementation project(':feature')

implementation project(':base')

implementation project(':gblib')

}

I also have gblib directory with a library of non-Android code. build.gradle from gb\lib

plugins {

id 'org.jetbrains.kotlin.jvm'

}

apply plugin: 'java-library'

dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])

compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

testImplementation 'junit:junit:4.12'

}

sourceCompatibility = "6"

targetCompatibility = "6"

repositories {

mavenCentral()

}

compileKotlin {

kotlinOptions {

jvmTarget = "1.8"

}

}

compileTestKotlin {

kotlinOptions {

jvmTarget = "1.8"

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值