任务 ':react-native-firebase:compileDebugJavaWithJavac' 执行失败。 #2099、
Execution failed for task ':react-native-firebase:compileDebugJavaWithJavac'. #2099 ,
我在 expo 中遇到了这个错误,我再次安装了 firebase/app,安装了 jetifier 并尝试了 运行 npx jetify 命令我也再次遇到了同样的错误
Execution failed for task ':react-native-firebase:compileDebugJavaWithJavac'. #2099
import * as React from "react";
import {
Text,
View,
StyleSheet,
TextInput,
Button,
Alert,
ActivityIndicator,
Platform,
} from "react-native";
import * as FirebaseRecaptcha from "expo-firebase-recaptcha";
import { initializeApp } from "firebase/app";
import {
getAuth,
PhoneAuthProvider,
signInWithCredential,
} from "firebase/auth";
const FIREBASE_CONFIG = {
//your credentials here firebase
};
try {
if (FIREBASE_CONFIG.apiKey) {
initializeApp(FIREBASE_CONFIG);
}
} catch (err) {
console.log(err);
}
const auth = getAuth();
// const app = getApp();
export default function PhoneAuthScreen() {
const recaptchaVerifier = React.useRef(null);
const verificationCodeTextInput = React.useRef(null);
const [phoneNumber, setPhoneNumber] = React.useState("");
const [verificationId, setVerificationId] = React.useState("");
const [verifyError, setVerifyError] = React.useState();
const [verifyInProgress, setVerifyInProgress] = React.useState(false);
const [verificationCode, setVerificationCode] = React.useState("");
const [confirmError, setConfirmError] = React.useState();
const [confirmInProgress, setConfirmInProgress] = React.useState(false);
const isConfigValid = !!FIREBASE_CONFIG.apiKey;
return (
<View style={styles.container}>
<View style={styles.content}>
<FirebaseRecaptcha.FirebaseRecaptchaVerifierModal
ref={recaptchaVerifier}
firebaseConfig={FIREBASE_CONFIG}
/>
<Text style={styles.title}>Firebase Phone Auth</Text>
<Text style={styles.subtitle}>using expo-firebase-recaptcha</Text>
<Text style={styles.text}>Enter phone number</Text>
<TextInput
style={styles.textInput}
autoFocus={isConfigValid}
autoCompleteType="tel"
keyboardType="phone-pad"
textContentType="telephoneNumber"
placeholder="+1 999 999 9999"
editable={!verificationId}
onChangeText={(phoneNumber) => setPhoneNumber(phoneNumber)}
/>
<Button
title={`${verificationId ? "Resend" : "Send"} Verification Code`}
disabled={!phoneNumber}
onPress={async () => {
const phoneProvider = new PhoneAuthProvider(auth);
try {
setVerifyError(undefined);
setVerifyInProgress(true);
setVerificationId("");
const verificationId = await phoneProvider.verifyPhoneNumber(
phoneNumber,
recaptchaVerifier.current
);
setVerifyInProgress(false);
setVerificationId(verificationId);
verificationCodeTextInput.current?.focus();
} catch (err) {
setVerifyError(err);
setVerifyInProgress(false);
}
}}
/>
{verifyError && (
<Text style={styles.error}>{`Error: ${verifyError.message}`}</Text>
)}
{verifyInProgress && <ActivityIndicator style={styles.loader} />}
{verificationId ? (
<Text style={styles.success}>
A verification code has been sent to your phone
</Text>
) : undefined}
<Text style={styles.text}>Enter verification code</Text>
<TextInput
ref={verificationCodeTextInput}
style={styles.textInput}
// editable={verificationId}
placeholder="123456"
onChangeText={(verificationCode) =>
setVerificationCode(verificationCode)
}
/>
<Button
title="Confirm Verification Code"
disabled={!verificationCode}
onPress={async () => {
try {
setConfirmError(undefined);
setConfirmInProgress(true);
const credential = PhoneAuthProvider.credential(
verificationId,
verificationCode
);
const authResult = await signInWithCredential(auth, credential);
console.log(authResult, "authresult");
setConfirmInProgress(false);
setVerificationId("");
setVerificationCode("");
verificationCodeTextInput.current?.clear();
Alert.alert("Phone authentication successful!");
} catch (err) {
setConfirmError(err);
setConfirmInProgress(false);
}
}}
/>
{confirmError && (
<Text style={styles.error}>{`Error: ${confirmError.message}`}</Text>
)}
{confirmInProgress && <ActivityIndicator style={styles.loader} />}
</View>
{!isConfigValid && (
<View style={styles.overlay} pointerEvents="none">
<Text style={styles.overlayText}>
To get started, set a valid FIREBASE_CONFIG in App.tsx.
</Text>
</View>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
},
content: {
marginTop: 50,
},
title: {
marginBottom: 2,
fontSize: 29,
fontWeight: "bold",
},
subtitle: {
marginBottom: 10,
opacity: 0.35,
fontWeight: "bold",
},
text: {
marginTop: 30,
marginBottom: 4,
},
textInput: {
marginBottom: 8,
fontSize: 17,
fontWeight: "bold",
},
error: {
marginTop: 10,
fontWeight: "bold",
color: "red",
},
success: {
marginTop: 10,
fontWeight: "bold",
color: "blue",
},
loader: {
marginTop: 10,
},
overlay: {
...StyleSheet.absoluteFillObject,
backgroundColor: "#FFFFFFC0",
justifyContent: "center",
alignItems: "center",
},
overlayText: {
fontWeight: "bold",
},
});
我在 expo 中遇到了这个错误,我再次安装了 firebase/app,安装了 jetifier 并尝试了 运行 npx jetify 命令我也再次遇到了同样的错误
Execution failed for task ':react-native-firebase:compileDebugJavaWithJavac'. #2099
import * as React from "react";
import {
Text,
View,
StyleSheet,
TextInput,
Button,
Alert,
ActivityIndicator,
Platform,
} from "react-native";
import * as FirebaseRecaptcha from "expo-firebase-recaptcha";
import { initializeApp } from "firebase/app";
import {
getAuth,
PhoneAuthProvider,
signInWithCredential,
} from "firebase/auth";
const FIREBASE_CONFIG = {
//your credentials here firebase
};
try {
if (FIREBASE_CONFIG.apiKey) {
initializeApp(FIREBASE_CONFIG);
}
} catch (err) {
console.log(err);
}
const auth = getAuth();
// const app = getApp();
export default function PhoneAuthScreen() {
const recaptchaVerifier = React.useRef(null);
const verificationCodeTextInput = React.useRef(null);
const [phoneNumber, setPhoneNumber] = React.useState("");
const [verificationId, setVerificationId] = React.useState("");
const [verifyError, setVerifyError] = React.useState();
const [verifyInProgress, setVerifyInProgress] = React.useState(false);
const [verificationCode, setVerificationCode] = React.useState("");
const [confirmError, setConfirmError] = React.useState();
const [confirmInProgress, setConfirmInProgress] = React.useState(false);
const isConfigValid = !!FIREBASE_CONFIG.apiKey;
return (
<View style={styles.container}>
<View style={styles.content}>
<FirebaseRecaptcha.FirebaseRecaptchaVerifierModal
ref={recaptchaVerifier}
firebaseConfig={FIREBASE_CONFIG}
/>
<Text style={styles.title}>Firebase Phone Auth</Text>
<Text style={styles.subtitle}>using expo-firebase-recaptcha</Text>
<Text style={styles.text}>Enter phone number</Text>
<TextInput
style={styles.textInput}
autoFocus={isConfigValid}
autoCompleteType="tel"
keyboardType="phone-pad"
textContentType="telephoneNumber"
placeholder="+1 999 999 9999"
editable={!verificationId}
onChangeText={(phoneNumber) => setPhoneNumber(phoneNumber)}
/>
<Button
title={`${verificationId ? "Resend" : "Send"} Verification Code`}
disabled={!phoneNumber}
onPress={async () => {
const phoneProvider = new PhoneAuthProvider(auth);
try {
setVerifyError(undefined);
setVerifyInProgress(true);
setVerificationId("");
const verificationId = await phoneProvider.verifyPhoneNumber(
phoneNumber,
recaptchaVerifier.current
);
setVerifyInProgress(false);
setVerificationId(verificationId);
verificationCodeTextInput.current?.focus();
} catch (err) {
setVerifyError(err);
setVerifyInProgress(false);
}
}}
/>
{verifyError && (
<Text style={styles.error}>{`Error: ${verifyError.message}`}</Text>
)}
{verifyInProgress && <ActivityIndicator style={styles.loader} />}
{verificationId ? (
<Text style={styles.success}>
A verification code has been sent to your phone
</Text>
) : undefined}
<Text style={styles.text}>Enter verification code</Text>
<TextInput
ref={verificationCodeTextInput}
style={styles.textInput}
// editable={verificationId}
placeholder="123456"
onChangeText={(verificationCode) =>
setVerificationCode(verificationCode)
}
/>
<Button
title="Confirm Verification Code"
disabled={!verificationCode}
onPress={async () => {
try {
setConfirmError(undefined);
setConfirmInProgress(true);
const credential = PhoneAuthProvider.credential(
verificationId,
verificationCode
);
const authResult = await signInWithCredential(auth, credential);
console.log(authResult, "authresult");
setConfirmInProgress(false);
setVerificationId("");
setVerificationCode("");
verificationCodeTextInput.current?.clear();
Alert.alert("Phone authentication successful!");
} catch (err) {
setConfirmError(err);
setConfirmInProgress(false);
}
}}
/>
{confirmError && (
<Text style={styles.error}>{`Error: ${confirmError.message}`}</Text>
)}
{confirmInProgress && <ActivityIndicator style={styles.loader} />}
</View>
{!isConfigValid && (
<View style={styles.overlay} pointerEvents="none">
<Text style={styles.overlayText}>
To get started, set a valid FIREBASE_CONFIG in App.tsx.
</Text>
</View>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
},
content: {
marginTop: 50,
},
title: {
marginBottom: 2,
fontSize: 29,
fontWeight: "bold",
},
subtitle: {
marginBottom: 10,
opacity: 0.35,
fontWeight: "bold",
},
text: {
marginTop: 30,
marginBottom: 4,
},
textInput: {
marginBottom: 8,
fontSize: 17,
fontWeight: "bold",
},
error: {
marginTop: 10,
fontWeight: "bold",
color: "red",
},
success: {
marginTop: 10,
fontWeight: "bold",
color: "blue",
},
loader: {
marginTop: 10,
},
overlay: {
...StyleSheet.absoluteFillObject,
backgroundColor: "#FFFFFFC0",
justifyContent: "center",
alignItems: "center",
},
overlayText: {
fontWeight: "bold",
},
});